-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
sstables: parse(summary): reserve positions vector #21767
sstables: parse(summary): reserve positions vector #21767
Conversation
🔴 CI State: FAILURE✅ - Build Build Details:
|
@@ -507,7 +507,7 @@ future<> parse(const schema& schema, sstable_version_types v, random_access_read | |||
|
|||
// Positions are encoded in little-endian. | |||
auto b = buf.get(); | |||
s.positions = utils::chunked_vector<pos_type>(); | |||
s.positions.reserve(s.header.size + 1); |
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 looks like we wanted to reset the positions to empty vector, in case it had content.
I see we don't do this consistently with all members, but maybe we should still keep the reset just in case.
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.
okay, I'll make sure it's still needed.
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.
I don't see where the summary component is reused, so I don't think this resetting is required.
We only call parse from
Line 1318 in cd2a2bd
co_return co_await read_simple<component_type::Summary>(_components->summary); |
After checking
Lines 1308 to 1310 in cd2a2bd
if (_components->summary) { | |
co_return; | |
} |
So we don't reuse the object.
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.
I'd suggest to add an explanation in the commit why it can go away. I'd expect a separate commit for removing the reset, but maybe that's bikeshedding since it's a simple change.
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.
I would add a comment in front of this function saying it can only be called once.
But, wouldn't it be easier just to allow it to be called twice? I.e., leave the reset as in the old code - and then add the reserve() you wanted to add?
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.
But we didn't reset s.entries
before so it was never supposed to work this way.
We don't need to invent new use cases to excuse some old artifact.
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.
That's a good point.
We know the number of positions in advance so reserve the chunked_vector capacity for that. Note: reservation replaces the existing reset of the positions member. This is safe since we parse the summary only once as sstable::read_summary() returns early if the summary component is already populated. Signed-off-by: Benny Halevy <[email protected]>
7ee6c18
to
f86d498
Compare
|
🟢 CI State: SUCCESS✅ - Build Build Details:
|
@scylladb/scylla-maint please consider merging |
We know the number of positions in advance
so reserve the chunked_vector capacity for that.