You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up parse ~15% by reusing the last line in Input#fromOffset - #2173
Input#fromOffset() did a binary search over all line starts on every call, and getLineToIndex() built the table with css.split('\n'), allocating a string per line. The parser asks for positions in increasing order, so the answer is almost always the line from the previous call or the next one (on bootstrap.css: 11,098 same line, 9,849 next line, 1,060 other). This checks those two lines first, falls back to the binary search otherwise, and builds the line table with an indexOf loop.
postcss.parse(bootstrap.css).toString(), the "PostCSS" case from postcss/benchmark, on current Bootstrap dist/css/bootstrap.css (496 KB), Node 26.3, Apple M5. 7 alternating processes per side, each the median of 40 runs after 30 warmup:
median of 7
range
main
10.73 ms
10.04 to 12.07
this PR
9.07 ms
8.70 to 10.49
That is about 15% less time per parse. bootstrap.min.css (one long line) shows no measurable change either way.
Output is identical to main (AST JSON with positions, CSS and inline source maps) on bootstrap.css and all 30 postcss-parser-tests cases, and fromOffset matches main on 62,000 random offsets queried in random order. pnpm unit, eslint, check-dts and size-limit pass.
Summary by CodeRabbit
Performance
Improved how source positions are located in CSS input, which can make repeated position lookups more efficient.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 3f813f35-f79e-4c1a-8a7f-d765f6bd6105
📥 Commits
Reviewing files that changed from the base of the PR and between f1aca7e and 7117d14.
📒 Files selected for processing: 1
lib/input.js
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
The line-start offset index now uses a newline scan. fromOffset caches the last located line and uses it to narrow subsequent searches.
Changes: Line Offset Lookup
Layer / File(s)
Summary
Build and search line offsets lib/input.js
getLineToIndex scans newline positions to build line-start offsets. fromOffset uses the cached line position to narrow its binary search and stores the resulting line index.
The offset lookup preserves line and column results for parser positions, including EOF and out-of-order queries. No concrete merge-blocking behavior change is evident.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main performance change: reusing the last line in Input#fromOffset to speed up parsing.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Input#fromOffset()did a binary search over all line starts on every call, andgetLineToIndex()built the table withcss.split('\n'), allocating a string per line. The parser asks for positions in increasing order, so the answer is almost always the line from the previous call or the next one (on bootstrap.css: 11,098 same line, 9,849 next line, 1,060 other). This checks those two lines first, falls back to the binary search otherwise, and builds the line table with anindexOfloop.postcss.parse(bootstrap.css).toString(), the "PostCSS" case from postcss/benchmark, on current Bootstrapdist/css/bootstrap.css(496 KB), Node 26.3, Apple M5. 7 alternating processes per side, each the median of 40 runs after 30 warmup:That is about 15% less time per parse.
bootstrap.min.css(one long line) shows no measurable change either way.Output is identical to main (AST JSON with positions, CSS and inline source maps) on bootstrap.css and all 30 postcss-parser-tests cases, and
fromOffsetmatches main on 62,000 random offsets queried in random order.pnpm unit, eslint, check-dts and size-limit pass.Summary by CodeRabbit