-
Notifications
You must be signed in to change notification settings - Fork 94
[LogServer] Reduce heap allocations for db keys #3624
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
Conversation
let value_bytes = DataRecordEncoder::from(payload).encode_to_disk_format(buffer); | ||
DataRecordKey::new(store_message.header.loglet_id, offset).to_binary_array(); | ||
let encoder = DataRecordEncoder::from(payload); | ||
buffer.reserve(encoder.estimated_encode_size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoid unnecessary memory ballooning since it'll try to allocate a single buffer that's big enough for all records combined although we just need one big enough for the biggest record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! LGTM and +1 for merging
let mut buf = [0u8; Self::size()]; | ||
let mut b = &mut buf[..]; | ||
KeyPrefix::new(KeyPrefixKind::DataRecord, loglet_id).encode_exclusive_upper_bound(&mut b); | ||
(&mut b).put_u64(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the array is already initialised with 0 on allocation. in line 116, this call is not necessary imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's true, but it'd be an implicit assumption that future eyes would miss.
- In log-server, keys have fixed lengths. This PR avoids small heap allocations when generating rocksdb keys. - Fixes a bug where we overshoot ths writer's buffer size to account for the entire batch although we don't need to do that.
Uh oh!
There was an error while loading. Please reload this page.