Skip to content

perf: optimize advance() with lazy line/column tracking#148

Merged
bartveneman merged 1 commit intomainfrom
perf/advance
Feb 26, 2026
Merged

perf: optimize advance() with lazy line/column tracking#148
bartveneman merged 1 commit intomainfrom
perf/advance

Conversation

@bartveneman
Copy link
Member

  • Replace per-character column tracking with lazy computation via getter
  • Inline newline check using char_types bitmask to avoid function call
  • Add seek() method for encapsulated lexer repositioning
  • Update all sub-parsers to use seek() instead of direct property writes

Column is now computed as pos - _line_offset + 1 only when accessed, eliminating column++ on ~99% of characters (non-newlines).

- Replace per-character column tracking with lazy computation via getter
- Inline newline check using char_types bitmask to avoid function call
- Add seek() method for encapsulated lexer repositioning
- Update all sub-parsers to use seek() instead of direct property writes

Column is now computed as `pos - _line_offset + 1` only when accessed,
eliminating column++ on ~99% of characters (non-newlines).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bartveneman bartveneman merged commit 557e0d7 into main Feb 26, 2026
5 checks passed
@bartveneman bartveneman deleted the perf/advance branch February 26, 2026 19:14
@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2026

Bundle Report

Changes will increase total bundle size by 6 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@projectwallace/css-parser-esm 146.71kB 6 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @projectwallace/css-parser-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
parse-*.js -92 bytes 25.97kB -0.35%
parse-*.js -92 bytes 22.88kB -0.4%
parse-*.js -22 bytes 8.48kB -0.26%
parse-*.js -36 bytes 7.15kB -0.5%
parse-*.js -46 bytes 8.47kB -0.54%
tokenize.js 394 bytes 18.9kB 2.13%
char-*.js -100 bytes 1.46kB -6.43%

Files in parse-*.js:

  • ./src/parse-selector.ts → Total Size: 24.59kB

Files in parse-*.js:

  • ./src/parse-atrule-prelude.ts → Total Size: 22.08kB

Files in parse-*.js:

  • ./src/parse-anplusb.ts → Total Size: 8.11kB

Files in parse-*.js:

  • ./src/parse-declaration.ts → Total Size: 6.5kB

Files in parse-*.js:

  • ./src/parse-value.ts → Total Size: 7.84kB

Files in tokenize.js:

  • ./src/tokenize.ts → Total Size: 18.3kB

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.87%. Comparing base (0fc9a60) to head (de388a6).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/tokenize.ts 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
- Coverage   94.96%   94.87%   -0.09%     
==========================================
  Files          16       16              
  Lines        2721     2714       -7     
  Branches      712      712              
==========================================
- Hits         2584     2575       -9     
- Misses        137      139       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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