Skip to content

Replace Lazy<FxHashMap> static lookups with phf::Map#93096

Open
mmastrac wants to merge 1 commit intommastrac/drop-once-cellfrom
mmastrac/phf-static-maps
Open

Replace Lazy<FxHashMap> static lookups with phf::Map#93096
mmastrac wants to merge 1 commit intommastrac/drop-once-cellfrom
mmastrac/phf-static-maps

Conversation

@mmastrac
Copy link
Copy Markdown
Contributor

@mmastrac mmastrac commented Apr 21, 2026

What

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

Copy link
Copy Markdown
Contributor Author

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will improve performance by 3.57%

⚡ 1 improved benchmark
✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation app-page-turbo.runtime.prod.js[full] 641.3 ms 619.2 ms +3.57%

Comparing mmastrac/phf-static-maps (4c8550e) with canary (c526347)2

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on mmastrac/drop-once-cell (b4c897f) during the generation of this report, so canary (c526347) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mmastrac mmastrac marked this pull request as ready for review April 21, 2026 17:01
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`.
@mmastrac mmastrac force-pushed the mmastrac/drop-once-cell branch from bd2527c to b4c897f Compare April 21, 2026 20:13
@mmastrac mmastrac force-pushed the mmastrac/phf-static-maps branch from f0ad205 to 4c8550e Compare April 21, 2026 20:13
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