Skip to content

perf(lint): optimize noIrregularWhitespace rule - #9111

Merged
ematipico merged 2 commits into
biomejs:mainfrom
Jayllyz:perf/no-irregular-whitespace
Feb 17, 2026
Merged

perf(lint): optimize noIrregularWhitespace rule#9111
ematipico merged 2 commits into
biomejs:mainfrom
Jayllyz:perf/no-irregular-whitespace

Conversation

@Jayllyz

@Jayllyz Jayllyz commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Generated by Opus 4.6 with a plan, manually tested on my locals repos.

Summary

I noticed using the rule profiler (really useful thanks) that this rule was the slowest for me. The initial goal here was to speed up the rule for non-matching files. The performance gain isn't huge, but I think its still worth it, around 10% from what i've tested in debug mode

Test Plan

Unit test + manual test on my repos.

Docs

@changeset-bot

changeset-bot Bot commented Feb 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e83a65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS and super languages labels Feb 16, 2026
@codspeed-hq

codspeed-hq Bot commented Feb 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 96 skipped benchmarks1


Comparing Jayllyz:perf/no-irregular-whitespace (7e83a65) with main (b99e7db)

Open in CodSpeed

Footnotes

  1. 96 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.

@Jayllyz
Jayllyz marked this pull request as ready for review February 16, 2026 22:16
@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉


Walkthrough

Refactors the noIrregularWhitespace lints for CSS and JavaScript. Introduces a central is_irregular_whitespace(char) helper, removes the previous static character set, and adds early-return checks to skip work when no irregular characters are present. CSS handling now accepts a CssSyntaxNode and iterates tokens via syntax.descendants_tokens(Direction::Next); JS processing consolidates leading and trailing trivia scanning. No public API changes.

Suggested reviewers

  • ematipico
  • dyc3
  • chansuke
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: a performance optimisation of the noIrregularWhitespace lint rule.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation (rule profiler identified slowness), the approach (optimising for non-matching files), and results (approximately 10% improvement).
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
Verify each finding against the current code and only fix it if needed.


In @.changeset/new-dolls-flow.md:
- Line 5: Fix the typo in the changeset line that reads "Sightly improved
performance of
[`noIrregularWhitespace`](https://biomejs.dev/linter/rules/no-irregular-whitespace/)..."
by changing "Sightly" to "Slightly" so the sentence correctly starts "Slightly
improved performance of `noIrregularWhitespace`...".

Comment thread .changeset/new-dolls-flow.md Outdated
@Jayllyz
Jayllyz force-pushed the perf/no-irregular-whitespace branch from 1aba52a to ab0d96b Compare February 16, 2026 22:23
@ematipico

ematipico commented Feb 16, 2026

Copy link
Copy Markdown
Member

I don't think the rule is slow per se, I believe it's slow because it must look at all the spaces inside a document

@dyc3 dyc3 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.

This makes sense. match statements get the compiler to vectorize the comparisons a bit better, ive seen it on compiler explorer before. Regardless, its less code overall which is always a good thing.

Very happy the rule profiler helped find this!

@dyc3

dyc3 commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Just curious @Jayllyz, you mentioned you tested in debug mode. Did you try in release mode? Debug mode makes biome significantly slower.

@ematipico
ematipico merged commit 4fb55cf into biomejs:main Feb 17, 2026
21 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 17, 2026
@Jayllyz
Jayllyz deleted the perf/no-irregular-whitespace branch February 17, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-CSS Language: CSS and super languages L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants