Optimize FileSource::get_path with single-pass string construction#2
Draft
avalanche-staging[bot] wants to merge 1 commit into
Draft
Optimize FileSource::get_path with single-pass string construction#2avalanche-staging[bot] wants to merge 1 commit into
FileSource::get_path with single-pass string construction#2avalanche-staging[bot] wants to merge 1 commit into
Conversation
|
(Automated Close) Please do not file pull requests here, see https://firefox-source-docs.mozilla.org/contributing/how_to_submit_a_patch.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimizes
FileSource::get_pathinintl/l10n/rust/l10nregistry-rs/src/source/mod.rsby replacing a multi-allocation string construction pattern with a single-pass approach.Before
This performs 3 heap allocations:
locale.to_string()— intermediateStringstr::replace(...)— allocates a newStringwithStrSearcheroverheadformat!(...)— final concatenation into yet anotherStringAfter
This performs 1 allocation with 0 reallocs:
String::with_capacitypre-allocates the bufferwrite!(result, "{}", locale)formats the locale directly into the buffer (no intermediateString)str::findreplacesStrSearcherwith a simpler substring searchBenchmark Results (simulation mode)
Source benchmarks show 35–45% instruction count reduction, with zero regressions on solver, registry, or preferences benchmarks:
Other changes
rustc-hash: Updated from v1 to v2 inl10nregistry-rs/Cargo.tomlto resolve type conflicts with transitive dependencies (fluent-bundle,fluent-fallback)criterion = "0.3"withcodspeed-criterion-compatin dev-dependencies and added a CodSpeed CI workflow