capnproto / go-capnp

Cap'n Proto library and code generator for Go
https://capnproto.org
Other
1.2k stars 108 forks source link

message: Fix reuse of first segment #556

Closed matheusd closed 1 month ago

matheusd commented 6 months ago

This fixes the Message's Reset() call to allow reuse of the first segment.

Prior to this fix, the first segment was discarded after the first Reset call, effectively causing a new segment to be initialized on every Reset call.

By reusing the first segment, the number of heap allocations is reduced and therefore performance is increased in use cases where the message object is reused.

The fix involved associtating the segment to the message and fixing checks to ensure the data of the segment is re-allocated after the reset.

A benchmark is included to show the current performance of this.

Part of #554

lthibault commented 6 months ago

Test failures seems unrelated. Re-running.

Thank you for submitting this -- I am currently traveling, but will track this as closely as possible.

matheusd commented 2 months ago

Updated.