Skip to content

perf: lint stylesheets over a pool only once a batch is big enough - #399

Merged
alexander-akait merged 1 commit into
mainfrom
perf/stylelint-threads
Oct 30, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
perf/stylelint-threads

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Refs #374.

This PR addresses the extra memory the reporter saw in their latest reproduction (859 TS/TSX files, 791 SCSS files, typed ESLint, Stylelint and the TypeScript check). It has two parts: a fix for Stylelint's worker pool, and a README note on ts-loader. The plugin doesn't change anyone's webpack config.

1. Stylelint: start the pool only when it pays off

With threads on, the Stylelint check started a pool of workers whatever the batch size, and each worker loads Stylelint and its config again. For small stylesheets that costs more than linting them. Now a batch goes over the pool only once its files add up to 2 MB, and is linted on webpack's thread below that. Once started, the pool is kept for later large batches.

Measured on the reporter's project, cold builds, four cores, 791 stylesheets. Each pair below was measured in the same session, and the first three rows used the reporter's two-rule config:

                                         time          whole process tree
no checks                                9.2–10.7 s    462–496 MB
stylelint-webpack-plugin                 10.4–11.3 s   479–515 MB
this check over the pool (main)          12.4–13.7 s   654–668 MB
this check on webpack's thread           10.5–11.3 s   506–533 MB

pool vs webpack's thread, stylelint-config-standard-scss
68 KB of stylesheets     14.6–15.1 s vs 13.3–13.5 s
0.9 MB                   23.2–23.8 s vs 22.1–22.6 s
4.5 MB                   49.5–52.5 s vs 54.0–56.6 s   ← the pool wins here

The threshold sits between the last two sizes.

2. README: transpileOnly when migrating from fork-ts-checker

ts-loader turns transpileOnly on by itself when it finds ForkTsCheckerWebpackPlugin in the config (ts-loader/dist/index.js:224-237). The reporter never wrote that option, so after removing fork-ts-checker, ts-loader type-checks the whole program inside the build again. That duplicates the TypeScript check's work and reports each type error twice. The "From fork-ts-checker-webpack-plugin" checklist now says to set it, and "Making it faster" links there.

The reporter's project, cold builds, with this branch:

                                         time          whole process tree
eslint + stylelint + fork-ts plugins     17.6–20.3 s   1,281–1,389 MB
1.1.1, config as reported                27.6 s        1,691–1,714 MB   (earlier runs)
this branch, config as reported          24.5–25.2 s   1,557–1,565 MB
this branch + transpileOnly: true        19.1–19.2 s   1,304–1,407 MB

Their own memory numbers come from process.memoryUsage().heapUsed, which leaves out fork-ts-checker's child process, so they overstate the gap. The table above is the peak memory (RSS) of the whole process tree.

Tests

  • test/stylelint/threads.test.js adds two tests.
    • A small batch is linted on webpack's thread, and a 3 MB one over the pool. The test can tell which ran it through the recorder mock, which only sees calls made on its own thread.
    • When the options can't be sent to a worker (a formatter function), a large batch falls back to webpack's thread.
  • The first test fails on main. Branch coverage of src/checks/stylelint.js is 100%.
  • Locally, npm run lint passes and the full suite (372 tests) passes.


Generated by Claude Code

Summary by CodeRabbit

  • Performance
    • Stylelint now uses a worker pool for batches of 2 MB or larger; smaller batches are linted on webpack’s thread.
    • When a worker pool cannot be created, linting falls back to webpack’s thread.
  • Documentation
    • Updated Stylelint guidance to explain the batch-size threshold and worker pooling.
    • Migration and performance guidance now recommends setting transpileOnly: true on ts-loader when using a separate TypeScript check.

The Stylelint check started a pool of workers whenever threads allowed
it, and each worker loaded Stylelint and its config again. For small
stylesheets that costs more than linting them: over the 791 stylesheets
of the project in #374, a cold build took 12.4-13.7 s and 654-668 MB
with the pool and 10.5-11.3 s and 506-533 MB on webpack's thread. A
batch is now linted over the pool only once its files add up to 2 MB;
at 4.5 MB the pool was 4 s faster.

The README now says to set transpileOnly on ts-loader when moving from
fork-ts-checker-webpack-plugin: ts-loader turns it on by itself when it
sees that plugin, so without it the program was type checked twice.
Refs #374.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FhutQipYi25fJ4rs9WE1c
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.70%. Comparing base (36731b5) to head (d086225).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #399   +/-   ##
=======================================
  Coverage   99.69%   99.70%           
=======================================
  Files          21       21           
  Lines        6630     6667   +37     
=======================================
+ Hits         6610     6647   +37     
  Misses         20       20           

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Walkthrough

Stylelint now uses the local linter for batches below 2 MiB and creates or reuses a worker pool for batches at or above that threshold. If pool creation fails, it uses the local linter. Tests cover batch-size dispatch and function-valued formatters. The README documents Stylelint pooling and adds ts-loader migration guidance for transpileOnly: true.

Priority: Low

Merge Risk: Minimal · up to d0862

No merge-blocking behavior was identified. Strengthening the large-batch test would improve confidence in worker dispatch.

Pre-merge checks: Passed 5
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: Stylelint uses the worker pool only when a stylesheet batch is large enough.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (2 skipped: 2 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Biome (2.5.15)
src/checks/stylelint.js

Biome could not lint this file: configuration resulted in errors. Check the repository's Biome configuration and plugins.

test/stylelint/threads.test.js

Biome could not lint this file: configuration resulted in errors. Check the repository's Biome configuration and plugins.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

test/stylelint/threads.test.js

Oops! Something went wrong! :(

ESLint: 10.10.0

SyntaxError: Unexpected token ':'
at compileSourceTextModule (node:internal/modules/esm/utils:319:16)
at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:89:18)
at #translate (node:internal/modules/esm/loader:438:20)
at afterLoad (node:internal/modules/esm/loader:506:29)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:511:12)
at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:564:36)
at afterResolve (node:internal/modules/esm/loader:611:52)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:617:12)
at node:internal/modules/esm/loader:636:32
at TracingChannel.tracePromise (node:diagnostics_channel:370:14)

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Comments

Nitpick Make the large-batch test assert a result that the pool path returns.

56-84: Trivial · Functional Correctness · Quick win

Make the large-batch test assert a result that the pool path returns.

The big-batch check at test/stylelint/threads.test.js:77-78 only asserts that the main-thread recorder was not called. A pool path that skips linting would leave that count at 1, so the test would still pass. The return value of lintFiles([big]) is also never checked.

The recorder mock always returns { results: [] }, so the current test cannot tell whether the worker linted the batch. A regression that silently dropped large batches would pass this test. To close the gap, the mock needs to return a result for each file it lints, and the test needs to assert that result. Because other tests load the same mock, check those tests before changing it.

Open the source location


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4925762-ed59-431d-b1de-9fb1b19dbe4e
Commits

Reviewing files that changed from the base of the PR and between 7374078 and d086225.

Files selected for processing: 4
  • .changeset/stylelint-pool-by-size.md
  • README.md
  • src/checks/stylelint.js
  • test/stylelint/threads.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@alexander-akait
alexander-akait merged commit 7477d72 into main Oct 30, 2026
16 of 17 checks passed
@alexander-akait
alexander-akait deleted the perf/stylelint-threads branch October 30, 2026 13:49
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.

1 participant