Repository navigation
Conversation
The bundle cache stored items in a ChunkyVec whose first chunk reserves 32 elements (~6.4 KB for a bundle). A Localization usually caches one or two bundles, so most of that block is never used. Store each cached bundle behind its own Box in a plain Vec instead: references handed out by the cache stay valid because a Box never moves its contents, which keeps ChunkyVec's pin-safety guarantee while the storage now grows one element at a time. This also drops the chunky-vec dependency. Fixes projectfluent#407
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.
Fixes #407
Summary
Each
Localizationused to allocate an ~8 KB block the first time it formatted a message, because the bundle cache (Cache/AsyncCacheinfluent-fallback) stores bundles in aChunkyVecwhose first chunk reservesDEFAULT_CAPACITY = 32elements (~6.4 KB requested for a ~200 B bundle). ALocalizationnormally caches one bundle (en-US) or two (locale + en-US fallback), so most of that block is never used.This stores each cached bundle behind its own
Boxin a plainVec:Cache::get/Cache::push_getstay valid regardless of how theVecgrows, because aBoxnever moves its contents — this keeps the pin-safety guarantee that motivatedChunkyVec, addressing the caveat in the third option of the issue.chunky-vecdependency is dropped (options 1 and 2 would have required changes to that crate, whose API has no way to pick a chunk capacity).Verification
cargo test -p fluent-fallback— 3 unit + 9 integration + 2 doc tests pass.caching_few_bundles_avoids_chunk_sized_allocationscounts allocations in the 6–7 KB band while caching two bundle-sized (200 B) elements via a#[global_allocator]: it fails onmainwith exactly one 6400-byte request (32 × 200) and passes with this change; run 10× without flakes.references_stay_stable_across_growthkeeps references frompush_getacross further growth and reads them afterwards, pinning the address-stability guarantee.cargo test --workspace— pass.cargo fmt --all -- --check— clean.cargo clippy --all-features -- -Dwarnings— no new warnings from this change (cache.rs is clean; the remainingmust_useerror fromasync_traiton current stable reproduces identically onmain).