Replace Lazy<FxHashMap> static lookups with phf::Map#93096
Replace Lazy<FxHashMap> static lookups with phf::Map#93096mmastrac wants to merge 1 commit intommastrac/drop-once-cellfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will improve performance by 3.57%
Performance Changes
Comparing Footnotes
|
Four static lookup maps are fully const-expressible, so `phf_map!` gives
us better code:
- no LazyLock, no runtime map construction, no allocation;
- perfect hash picked at compile time;
- fewer dependencies (three crates drop rustc-hash, one adds phf).
Converted:
- `UNITS` in turbopack-image/process/svg.rs — `f64` values.
- `STATIC_LOCAL_METADATA`, `STATIC_GLOBAL_METADATA` in
next-core/next_app/metadata/mod.rs — `&'static [&'static str]` values.
- `FEATURE_MODULES` in next-core/next_shared/resolve.rs — value type
changed from `Vec<&'static str>` to `&'static [&'static str]`.
All four maps are consumed via `.get()` / `.contains_key()` or `.keys()`
followed by `.collect::<Vec<_>>()` into a `FxHashSet` — none of them
depend on a specific iteration order, so phf's hash-determined order is
safe. `match_metadata_file` signature updated to take
`&phf::Map<&'static str, &'static [&'static str]>`.
Adds `phf = { workspace = true }` to `next-core` and `turbopack-image`;
drops unused `rustc-hash` from `turbopack-image`.
bd2527c to
b4c897f
Compare
f0ad205 to
4c8550e
Compare

What
Trivial change: LazyLock<FxHashMap<...>> -> phf::Map.