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

message: Fix reuse of first segment #556

Merged
merged 1 commit into from
Jul 19, 2024

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.

message.go Show resolved Hide resolved
message.go Outdated Show resolved Hide resolved
segment.go Show resolved Hide resolved
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
Copy link
Contributor Author

Updated.

@lthibault lthibault merged commit b1fc0ec into capnproto:main Jul 19, 2024
0 of 4 checks passed
@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