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

syntax/utf8: avoid a spurious vector reallocation #1185

Merged
merged 1 commit into from Apr 22, 2024

Conversation

lucab
Copy link
Contributor

@lucab lucab commented Apr 22, 2024

This reworks Utf8Sequences logic in order to avoid allocating a 0-sized vector and immediately reallocating it for the initial element. Directly create the populated vector instead.

This reworks `Utf8Sequences` logic in order to avoid allocating a
0-sized vector and immediately reallocating it for the initial element.
Directly create the populated vector instead.
@BurntSushi
Copy link
Member

Can you say more about what motivated this change? Is this just something you happened to notice while reviewing the code, or did you notice something in a benchmark?

@lucab
Copy link
Contributor Author

lucab commented Apr 22, 2024

Hi @BurntSushi and thanks for the prompt reply.
I was looking at the memory usage patterns of rolldown through heaptrack, and this spot showed up as a potentially-spurious temporary allocation. The consumer side is here.
I do not have a specific benchmark for this.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Sounds good. I was mostly just curious. While I agree there is a potentially spurious alloc here (assuming the optimizer doesn't elide it), I doubt it matters relative to all the other work being done. But still, this seems like an improvement. Thank you!

@BurntSushi BurntSushi merged commit b12a276 into rust-lang:master Apr 22, 2024
16 checks passed
@lucab lucab deleted the ups/utf8-sequences-vec-alloc branch April 23, 2024 07:10
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.

None yet

2 participants