Skip to content

perf(packages/codegen): eagerly initialize mapNames - #25979

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_
Aug 24, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Aug 22, 2026

Copy link
Copy Markdown
Member

Previously mapNames property of state was lazily initialized - it started as null, and an array is only created when a named mapping is written.

Often lazy initialization is a good strategy, but in this case IMO it's a poor trade-off - it adds a check for every named mapping that's written in return for saving a single allocation per file, and only in files which produce a source map with no names. Allocating 1 empty array is very cheap.

overlookmotel commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates source-map generation to eagerly initialize mapNames, removing repeated lazy-initialization checks.

Changes:

  • Initialize mapNames alongside mapPositions.
  • Simplify named mapping writes.
  • Update source-map access and assertions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/codegen/src-js/state.ts Eagerly initializes mapNames.
packages/codegen/src-js/print/write.ts Removes lazy array initialization.
packages/codegen/src-js/print/source_map.ts Uses direct initialized-array access.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions branch from 59742d9 to dc29479 Compare August 22, 2026 09:39
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch from cd92cea to 57c3dd8 Compare August 22, 2026 09:40
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions branch from dc29479 to b660279 Compare August 22, 2026 10:31
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch from 57c3dd8 to 1652053 Compare August 22, 2026 10:31
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions branch from b660279 to f174d21 Compare August 22, 2026 13:33
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch from 1652053 to d6c729f Compare August 22, 2026 13:34
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Aug 24, 2026

camc314 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Aug 24, 7:24 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 24, 7:32 AM UTC: camc314 added this pull request to the Graphite merge queue.
  • Aug 24, 7:42 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #25978.
  • Aug 24, 7:42 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #25978.
  • Aug 24, 7:42 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 24, 7:47 AM UTC: camc314 added this pull request to the Graphite merge queue.
  • Aug 24, 8:24 AM UTC: This pull request was removed from the Graphite merge queue because the batch it was included in timed out. Please re-enqueue the PR to retry merge.
  • Aug 24, 8:54 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 24, 8:59 AM UTC: camc314 added this pull request to the Graphite merge queue.
  • Aug 24, 9:04 AM UTC: Merged by the Graphite merge queue.

@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Aug 24, 2026
@camc314 camc314 added 0-merge Merge with Graphite Merge Queue labels Aug 24, 2026 — with Graphite App
@graphite-app
graphite-app Bot changed the base branch from om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions to graphite-base/25979 August 24, 2026 07:43
graphite-app Bot pushed a commit that referenced this pull request Aug 24, 2026
Previously `mapNames` property of state was lazily initialized - it started as `null`, and an array is only created when a named mapping is written.

Often lazy initialization is a good strategy, but in this case IMO it's a poor trade-off - it adds a check for every named mapping that's written in return for saving a single allocation per file, and only in files which produce a source map with no names. Allocating 1 empty array is very cheap.
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch from d6c729f to 8621f31 Compare August 24, 2026 07:49
@graphite-app
graphite-app Bot changed the base branch from graphite-base/25979 to om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions August 24, 2026 07:49
Base automatically changed from om/08-18-perf_packages_codegen_split_recording_mappings_into_multiple_functions to main August 24, 2026 07:53
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Aug 24, 2026
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Aug 24, 2026
Previously `mapNames` property of state was lazily initialized - it started as `null`, and an array is only created when a named mapping is written.

Often lazy initialization is a good strategy, but in this case IMO it's a poor trade-off - it adds a check for every named mapping that's written in return for saving a single allocation per file, and only in files which produce a source map with no names. Allocating 1 empty array is very cheap.
@graphite-app
graphite-app Bot force-pushed the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch from 5cc70fe to 53f6270 Compare August 24, 2026 09:00
@graphite-app
graphite-app Bot merged commit 53f6270 into main Aug 24, 2026
29 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Aug 24, 2026
@graphite-app
graphite-app Bot deleted the om/08-18-perf_packages_codegen_eagerly_initialize_mapnames_ branch August 24, 2026 09:04
graphite-app Bot pushed a commit that referenced this pull request Aug 24, 2026
### 🚀 Features

- b6e9e5e minifier: Fold switch stmt whose parent is not block stmt (#25403) (Armano)

### 🐛 Bug Fixes

- 8a9bdbd estree: Include decorators in `FormalParameterRest ` spans (#26021) (camc314)
- 6f0c7cf minifier: Avoid merging `if` to `for` in sloppy mode when containing function declaration (#25638) (sapphi-red)
- 2cde1f6 rust: Address nightly deprecations (#25998) (Boshen)
- 6c5ad1b codegen: Only add mapping names for `PrivateIdentifier`s which have changed (#25958) (overlookmotel)
- 2dad1e0 parser: Track irregular line terminators in trivia (#25947) (camc314)
- 58ba651 minifier: Avoid merging `if` to `for` when the body contains a function declaration (#25637) (sapphi-red)
- a185ac3 codegen: Print `#` before private identifier in TS signature key (#25938) (overlookmotel)
- af82a07 minifier: Keep unary `+` when the other operand has side effects (#25645) (Kotaro Chikuba)

### ⚡ Performance

- 53f6270 packages/codegen: Eagerly initialize `mapNames` (#25979) (overlookmotel)
- 5b43c60 packages/codegen: Split recording mappings into multiple functions (#25978) (overlookmotel)
- cc947b5 packages/codegen: Reduce property lookups (#25977) (overlookmotel)
- c22a9cc packages/codegen: Combine condition checks (#25976) (overlookmotel)
- 215a6a5 packages/codegen: Add functions for writing/marking unnamed mappings (#25975) (overlookmotel)
- fe444cc codegen: Avoid allocations for single comment anchors (#25598) (camc314)
- a0aee81 minifier: Do not rebuild expression when substituting void to null (#25964) (Armano)
- 1004439 packages/codegen: Merge `mark` and `write` calls in `printImportAttributes` (#25972) (overlookmotel)
- 94c8a34 packages/codegen: Remove `node` param from `printString` and `printNonNegativeFloat` (#25971) (overlookmotel)
- 7e2b4b3 packages/codegen: `printNonNegativeFloat` write mapping directly (#25968) (overlookmotel)
- f09c8ab minifier: Avoid creation of unnecessary conditional expressions (#25931) (Armano)
- 53ff080 packages/codegen: Remove `lastWasPostfixClose` (#25888) (overlookmotel)

### 📚 Documentation

- 07de646 packages/codegen: Fix JSDoc comments on `write*` methods (#25966) (overlookmotel)
- 3b09c04 packages/codegen: Clarify comment (#25959) (overlookmotel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo