Skip to content

Conversation

@matheusd
Copy link
Contributor

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
Copy link
Collaborator

Test failures seems unrelated. Re-running.

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

@matheusd matheusd mentioned this pull request Apr 5, 2024
Copy link
Collaborator

@lthibault lthibault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall. Small changes requested inline.

@matheusd matheusd force-pushed the fix-msg-seg-reuse branch from bb0cdd3 to 332099c Compare June 18, 2024 18:41
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.
@matheusd matheusd force-pushed the fix-msg-seg-reuse branch from 332099c to f0b2970 Compare June 18, 2024 18:45
@matheusd
Copy link
Contributor Author

Updated.

@lthibault lthibault merged commit b1fc0ec into capnproto:main Jul 19, 2024
@matheusd matheusd deleted the fix-msg-seg-reuse branch July 20, 2024 09:22
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

Successfully merging this pull request may close these issues.

2 participants