perf(codegen): remove bounds check from SourcemapBuilder#19578
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
82902e3 to
fa07dee
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
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-rangegetto fetch/compare the next two bytes. - Add comments explaining why the loop increments
idxby 1 for non-ASCII bytes instead of attempting to skip full UTF-8 sequences.
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.
fa07dee to
b5fa195
Compare
### 🚀 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>

Follow-on after #19548.
Remove a bounds check from hot loop in
SourcemapBuilder::update_generated_line_and_columnby 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.