Skip to content

perf(codegen): remove bounds check from SourcemapBuilder#19578

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_
Feb 20, 2026
Merged

perf(codegen): remove bounds check from SourcemapBuilder#19578
graphite-app[bot] merged 1 commit intomainfrom
om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 20, 2026

Follow-on after #19548.

Remove a bounds check from hot loop in SourcemapBuilder::update_generated_line_and_column by doing only 1 bounds check to get next 2 bytes, instead of 2 bounds checks for each byte.

This optimization was taken from @cam314's original version of PR #19548.

While reviewing that PR I also thought I'd spied 2 other optimizations, but on reflection, I realized they were better left as is. Add comments to explain why.

Copy link
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 hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance labels Feb 20, 2026
@overlookmotel overlookmotel marked this pull request as ready for review February 20, 2026 14:47
Copilot AI review requested due to automatic review settings February 20, 2026 14:47
@overlookmotel overlookmotel force-pushed the om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_ branch from 82902e3 to fa07dee Compare February 20, 2026 14:49
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 20, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_ (fa07dee) with main (e316694)

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies a small performance-oriented tweak to SourcemapBuilder::update_generated_line_and_column by reducing bounds checks when detecting Unicode line separators (U+2028/U+2029) in the generated output, and adds clarifying comments about intentionally not adding additional work to the hot loop for uncommon Unicode cases.

Changes:

  • Replace two direct index reads (output[idx + 1], output[idx + 2]) with a single slice-range get to fetch/compare the next two bytes.
  • Add comments explaining why the loop increments idx by 1 for non-ASCII bytes instead of attempting to skip full UTF-8 sequences.

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Feb 20, 2026
Copy link
Contributor

camc314 commented Feb 20, 2026

Merge activity

Follow-on after #19548.

Remove a bounds check from hot loop in `SourcemapBuilder::update_generated_line_and_column` by doing only 1 bounds check to get next 2 bytes, instead of 2 bounds checks for each byte.

This optimization was taken from @cam314's original version of PR #19548.

While reviewing that PR I also thought I'd spied 2 other optimizations, but on reflection, I realized they were better left as is. Add comments to explain why.
@graphite-app graphite-app bot force-pushed the om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_ branch from fa07dee to b5fa195 Compare February 20, 2026 15:00
@graphite-app graphite-app bot merged commit b5fa195 into main Feb 20, 2026
21 checks passed
@graphite-app graphite-app bot deleted the om/02-20-perf_codegen_remove_bounds_check_from_sourcemapbuilder_ branch February 20, 2026 15:06
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 20, 2026
camc314 pushed a commit that referenced this pull request Feb 23, 2026
### 🚀 Features

- e814049 oxc_data_structure/rope: Add `get_offset_from_line_and_column`
(#18133) (Sysix)

### 🐛 Bug Fixes

- 7958b56 linter: Fix syntax error reporting in some output formatters.
(#19590) (connorshea)
- e316694 codegen: Avoid sourcemap panic on `U+2028`/`U+2029` (#19548)
(camc314)
- 933ff72 semantic: Emit correct error code for reserved type name
(#19545) (camc314)

### ⚡ Performance

- b5fa195 codegen: Remove bounds check from `SourcemapBuilder` (#19578)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants