Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow returning []byte in place of string fields #17

Closed
glycerine opened this issue Dec 28, 2015 · 0 comments
Closed

allow returning []byte in place of string fields #17

glycerine opened this issue Dec 28, 2015 · 0 comments

Comments

@glycerine
Copy link
Contributor

On v1, I was seeing alot of allocation due to string copying. So I added 2 small upgrades:

a) BenchmarkUnmarshalCapnpZeroCopyNoAlloc() in mem.go

b) Bytes() and TextList.AtBytes() methods that return the []byte slice directly instead of copying it to a string.

The reduction in memory allocation means that I can then read a ton of mmap-ed data and analyze the string fields, all while doing zero-allocation and having zero GC pressure.

See glycerine/go-capnproto@db36ab2

comparisons:

BenchmarkUnmarshalCapnp-4                    2000000           605 ns/op     766.08 MB/s         256 B/op          5 allocs/op              
BenchmarkUnmarshalCapnpZeroCopy-4           10000000           182 ns/op    2539.81 MB/s          88 B/op          3 allocs/op              
BenchmarkUnmarshalCapnpZeroCopyNoAlloc-4    100000000           24.9 ns/op  18668.12 MB/s          0 B/op          0 allocs/op   

and

BenchmarkWithoutStringBytes-4               20000000            78.6 ns/op        32 B/op          1 allocs/op   
BenchmarkStringBytes-4                      50000000            29.4 ns/op         0 B/op          0 allocs/op                              

It would be great to add similar API []byte access to v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant