Skip to content

Optimize parser hot-paths - #347

Merged
j9t merged 5 commits into
mainfrom
perf/parser-hot-paths
Aug 30, 2026
Merged

Optimize parser hot-paths#347
j9t merged 5 commits into
mainfrom
perf/parser-hot-paths

Conversation

@j9t

@j9t j9t commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Performance

    • Improved HTML parsing and minification performance, especially for common ASCII tag names and end tags.
    • Reduced overhead when processing trailing whitespace and repeated tags.
  • Bug Fixes

    • Improved handling of non-ASCII tag names during minification.
    • Updated tag-closing whitespace behavior for more consistent output.
  • Chores

    • Updated the package version to 8.3.1.
    • Refreshed several dependency versions.
  • Documentation

    • Added changelog entries describing the parser performance improvements.

j9t added 3 commits August 30, 2026 16:02
Replaced regex-based tag matching with manual character scans to minimize overhead. Adjusted functions like `parseStartTag`, `matchEndTag`, and `matchTagClose` to use fast-path ASCII processing while maintaining compatibility with existing logic.

(This commit message was AI-generated.)

Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
@socket-security

socket-security Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​node@​26.2.0 ⏵ 26.4.0100 +110081 +196100
Updatedvite@​8.2.1 ⏵ 8.2.29810082 +196100
Updatedterser@​5.50.0 ⏵ 5.51.2100 +110010095100
Updatedsvgo@​4.0.2 ⏵ 4.1.0100 +110010096100

View full report

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c76b96e3-7e5d-4ee5-a6ee-d18e3aa59e1f

📥 Commits

Reviewing files that changed from the base of the PR and between ae919c5 and 7ce3069.

📒 Files selected for processing (4)
  • backtest/html-minifier-next.config.json
  • src/htmlminifier.js
  • src/htmlparser.js
  • test/html.test.js

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

The parser and minifier replace selected regular-expression checks with character-code scans. The parser reuses lowercased tag names and packs tag-close results. Tests cover non-ASCII tag names. Package metadata and the changelog advance to version 8.3.1.

Changes

Parser and minifier performance changes

Layer / File(s) Summary
Parser tag scanning and state reuse
src/htmlparser.js, test/html.test.js
The parser scans common ASCII tag names directly, falls back to the qname regex when needed, packs tag-close results into an integer, reuses lowercased tag names for prevTag, and tests non-ASCII tag names.
Minifier end-tag scanning
src/htmlminifier.js, backtest/html-minifier-next.config.json
The minifier uses a hand-rolled end-tag matcher and a direct character-code check for trailing >. The backtest configuration disables newlines before tag closes.
Release metadata and dependency ranges
package.json, CHANGELOG.md
The package version changes to 8.3.1, dependency ranges are updated, and the changelog records the parser performance changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 7ce30

This PR optimizes parser and minifier hot paths while preserving the existing parser interface and fallback behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: parser hot-path performance optimizations, including hand-scanned tag matching and reduced redundant work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/parser-hot-paths

Warning

Some tools did not complete. Review the errors below.

🔧 ast-grep (0.45.2)
test/html.test.js

ast-grep timed out on this file


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@j9t
j9t requested a lite review from Copilot August 30, 2026 14:10

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

j9t added 2 commits August 30, 2026 16:31
Moved `matchPlainEndTag` to improve function organization and reduce duplication. Updated related tests to ensure correct handling of edge cases with non-ASCII tag names.

(This commit message was AI-generated.)

Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
…maxLineLength`)

Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
@j9t
j9t merged commit 7d43ecd into main Aug 30, 2026
10 checks passed
@j9t
j9t deleted the perf/parser-hot-paths branch August 30, 2026 14:51
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