Giter Site home page Giter Site logo

Better support for maps about vtprotobuf HOT 2 OPEN

planetscale avatar planetscale commented on July 19, 2024
Better support for maps

from vtprotobuf.

Comments (2)

vmg avatar vmg commented on July 19, 2024

Hi @ericrenard!

I can provide a sample proto file and modifications made if needed.

I would appreciate that. I've been playing around with potential ways to pool the maps but nothing was proving to be significantly faster. Can you share some code?

from vtprotobuf.

ericrenard avatar ericrenard commented on July 19, 2024

Hi,
Sorry for replying so late, I was busy with other stuff :p
I uploaded an example here : https://github.com/MolotovTv/benchvitess
You have sample_vtproto.pb.go.standard which is the currently generated pb file for included proto and sample_vtproto.pb.go which is my hacked version.
Basically what I'm doing is to use the pool when a map value is an object and to pool the map itself (which is maybe not worth it).

Pre changes benchmark:
BenchmarkMarshal/marshalStd-12 27 41980015 ns/op 2184862 B/op 200005 allocs/op
BenchmarkMarshal/marshalVT-12 87 12711687 ns/op 1384449 B/op 1 allocs/op
BenchmarkUnmarshal/unMarshalStd-12 266701 3751 ns/op 1274 B/op 24 allocs/op
BenchmarkUnmarshal/unMarshalVT-12 830570 1262 ns/op 1186 B/op 13 allocs/op
BenchmarkUnmarshal/unMarshalVTWithPool-12 830074 1295 ns/op 1186 B/op 13 allocs/op

Post changes benchmark:
BenchmarkMarshal/marshalStd-12 25 44627198 ns/op 2184793 B/op 200005 allocs/op
BenchmarkMarshal/marshalVT-12 84 15979075 ns/op 1384450 B/op 1 allocs/op
BenchmarkUnmarshal/unMarshalStd-12 322051 3813 ns/op 1274 B/op 24 allocs/op
BenchmarkUnmarshal/unMarshalVT-12 415844 2787 ns/op 1187 B/op 13 allocs/op
BenchmarkUnmarshal/unMarshalVTWithPool-12 967172 1215 ns/op 3 B/op 0 allocs/op

I think pooling the values from the map is always better, but obviously the more objects in the map, the most difference it makes, for ex with 1000 keys :

BenchmarkUnmarshal/unMarshalVTWithPool-12 7194 149844 ns/op 147475 B/op 1030 allocs/op
BenchmarkUnmarshal/unMarshalVTWithPool-12 9793 118702 ns/op 192 B/op 0 allocs/op

While the difference in terms of speed is not huge in a benchmark, I think it makes a lot of difference on the gc pressure in context of, for example, microservices that do mainly unmarshall/marshal stuff.

from vtprotobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.