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

Store boxed slices instead of Vec objects in Context #278

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

danielocfb
Copy link
Contributor

We never resize the unit ranges, units, or sup units that we parsed -- they stay what they were when we instantiated the Context object. As such, we don't need to store Vec objects, which include a capacity. Do what we do for the Functions type and just store boxed slices. Doing so cuts a machine word of each, but also trims heap allocations to the minimal size required in the process.

We never resize the unit ranges, units, or sup units that we parsed --
they stay what they were when we instantiated the Context object. As
such, we don't need to store Vec objects, which include a capacity. Do
what we do for the Functions type and just store boxed slices. Doing so
cuts a machine word of each, but also trims heap allocations to the
minimal size required in the process.

Signed-off-by: Daniel Müller <[email protected]>
@bjorn3
Copy link
Contributor

bjorn3 commented Jul 19, 2023

If capacity and size don't match trimming is expensive as it requires a copy of all data in many cases.

@philipc
Copy link
Contributor

philipc commented Jul 20, 2023

None of the benchmarks show any significant difference, so seems fine to me. Is this patch due to something you noticed in use, or only from code review?

@danielocfb
Copy link
Contributor Author

Is this patch due to something you noticed in use, or only from code review?

It's from code review.

If you don't like it then feel free to close, no hard feelings. But to me trimming in most places but not in others seems bogus, given that we are not modifying these structures afterwards by design.

@philipc philipc merged commit 390fb45 into gimli-rs:master Jul 20, 2023
@danielocfb danielocfb deleted the topic/boxes branch July 28, 2023 17:00
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.

4 participants