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
perf: lint stylesheets over a pool only once a batch is big enough - #399
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.
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
✅ 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.
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: 5
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 change: Stylelint uses the worker pool only when a stylesheet batch is large enough.
Docstring Coverage
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
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.
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.
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.
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.
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.
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
threadson, 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:
The threshold sits between the last two sizes.
2. README:
transpileOnlywhen migrating from fork-ts-checkerts-loaderturnstranspileOnlyon by itself when it findsForkTsCheckerWebpackPluginin the config (ts-loader/dist/index.js:224-237). The reporter never wrote that option, so after removing fork-ts-checker,ts-loadertype-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:
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.jsadds two tests.main. Branch coverage ofsrc/checks/stylelint.jsis 100%.npm run lintpasses and the full suite (372 tests) passes.Generated by Claude Code
Summary by CodeRabbit
transpileOnly: trueonts-loaderwhen using a separate TypeScript check.