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

fix: Optimize dynamic string building #491

Merged
merged 2 commits into from
Dec 15, 2024
Merged

Conversation

mwcampbell
Copy link
Contributor

This reduces intermediate allocations, especially when dynamically building a label.

One could imagine taking advantage of this in a self-voicing adapter to write the label, value, or text range directly into the buffer that contains the utterance to be spoken, and that buffer could be reused across utterances.

On Windows, this allows us to construct the dynamic string as UTF-16 in one pass, rather than constructing it as UTF-8 and then re-encoding it to UTF-16 in another pass, adding a temporary allocation.

This change happens to add 512 bytes to the binary size of a panic_immediate_abort build of the Windows hello_world example on x86-64. It doesn't have any effect on the binary size of that same example built as a normal release build with panic = "abort".

@mwcampbell mwcampbell force-pushed the optimize-string-building branch from 4ed2103 to a11788a Compare December 8, 2024 22:08
@DataTriny DataTriny merged commit a86901d into main Dec 15, 2024
9 checks passed
@DataTriny DataTriny deleted the optimize-string-building branch December 15, 2024 14:55
@github-actions github-actions bot mentioned this pull request Dec 15, 2024
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