Repository navigation
perf(hmr): cache chunk versions and avoid redundant allocations - #16673
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afc635ccef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
📦 Binary Size-limit
❌ Size increased by 8.00KB from 67.73MB to 67.74MB (⬆️0.01%) |
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Merging this PR will not alter performance
Comparing Footnotes
|
afc635c to
88851c0
Compare
Motivation
HotModuleReplacementChunkVersionsRuntimeModule(#16360) attaches to every runtime chunk and hasdependent_hash() == truealongside HMR'sfull_hashruntime module. Previously, each runtime chunk recomputedversions()up to 5–6 times per compilation (create_hashruntime pass,create_hashfull-hash pass,runtime_modules_code_generation,CreateChunkAssetsPass,generate_update, andget_update_data) without caching:get_all_referenced_chunks, rebuilt a freshBTreeMap<ChunkId, String>, allocated a heapStringper version, and re-serialized the entire 2D JSON array ingenerate().is_versioned()check allocated and discarded a fullVec<ModuleIdentifier>viaget_chunk_modules_identifier_by_source_type(...).is_empty().get_hmr_chunk_versioncallers duplicatedChunkKind::HotUpdateandRuntimeGlobals::HMR_CHUNK_VERSIONSguards across chunk formatters and always queriedcgc_runtime_requirements_artifact, even in non-HMR builds.Changes
BuildChunkGraphArtifact::is_runtime_chunkbacked by the precomputedruntime_chunksset (falling back toChunk::has_runtime) and reuse it acrossChunkGroup::get_loading_chunks,is_versioned,get_hmr_chunk_version, andHotModuleReplacementChunkVersionsRuntimeModule.O(1)version lookup: Fold!compilation.hot,ChunkKind::HotUpdate,is_runtime_chunk, andRuntimeGlobals::HMR_CHUNK_VERSIONSguards intoget_hmr_chunk_versionso chunk formatters share one entry point and non-HMR builds return immediately without map lookups.is_versionedtoadditional_chunk_runtime_requirements(its sole remaining caller) and replaceget_chunk_modules_identifier_by_source_type(...).is_empty()with the short-circuitinghas_chunk_module_by_source_type.(ChunkId, ChunkUkey)pairs once perHotModuleReplacementChunkVersionsRuntimeModulein aOnceLock<Box<[(ChunkId, ChunkUkey)]>>.chunk_hashes_artifact, store versions in a compact sortedArc<ChunkVersions>(Box<[(ChunkId, SmolStr)]>), and validate cached versions without allocation.Arc<ChunkVersions>directly inget_update_data().BTreeMaplookups ingenerate_update()with anO(C)two-pointer linear merge and direct JSON string formatting to avoid per-entry temporaryStringallocations.