Skip to content

fix(lint): type-check every file before rules run under --type-check - #955

Merged
camc314 merged 1 commit into
mainfrom
fix/lint-type-check-before-rules
Nov 10, 2026
Merged

camc314 merged 1 commit into
mainfrom
fix/lint-type-check-before-rules

Conversation

@camc314

@camc314 camc314 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With --type-check, each checker used to type-check a file and then run the rules on it, one file at a time. A rule's type query could then build a type before the checking that tsrs --noEmit does. Any error the checker hit there had no location, so it was reported on the tsconfig as a global diagnostic. Checking a later file on the same checker also lost the error, because the type was already cached.

run_program now runs its per-file loop twice: first type-checking only, then rules only, on the same checkers. It collects the program's global diagnostics between the two passes, so diagnostics recorded while answering rule queries are never reported.

Example

a.ts (listed, with no-unsafe-enum-assignment):

interface Box<T> {
  take(value: { a: T } | { b: T }): void;
}
export type AnyBox = Box<1> | Box<2> | /* … */ | Box<17>;
export declare const box: AnyBox;
export const wide: Box<unknown> = box;

b.ts:

import { box } from './a';
box.take({ a: 1 } as never);
Reported
tsgo --noEmit / tsrs --noEmit b.ts(2,1): error TS2590
tsrs-lint --type-check, before tsconfig.json:1:1 TS2590
tsrs-lint --type-check, after b.ts(2,1) TS2590

The issue's own program, a.ts alone, now reports nothing, which matches tsgo and tsrs --noEmit.

Dropping the global diagnostics that a checker adds while rules run, as the issue suggests, would not be enough: b.ts would still miss its error.

Fixes #941

Real-world case

On t3code-server (a catalog project), --type-check on main reports packages/contracts/tsconfig.json:1:1 TS2590. This branch doesn't, which matches tsgo and tsrs --noEmit: neither reports any error for that project. Apart from that one diagnostic, the output is identical.

Performance

The two passes don't repeat work: each file is still type-checked once and linted once. The only added cost is a second trip through the checker pool, and on large projects with --type-check the rules running after every file is checked rather than right after their own file.

These numbers compare release tsrs-lint builds of main and this branch with all 61 rules. Wall time and peak RSS are medians of 8 interleaved main/branch pairs on default checkers. Instructions retired are medians of 3 runs with one checker (RAYON_NUM_THREADS=1). Measured on macOS arm64 with /usr/bin/time -l (10 ms wall resolution).

Project --type-check Wall Peak RSS Instructions (1 checker)
webpack off 0.43s → 0.43s 418 → 416 MiB 14.80G → 14.80G (+0.04%)
webpack on 0.53s → 0.53s 520 → 519 MiB 19.12G → 19.11G (−0.06%)
drizzle-orm off 0.29s → 0.30s 437 → 436 MiB 7.49G → 7.50G (+0.01%)
drizzle-orm on 0.33s → 0.34s 508 → 511 MiB 8.99G → 9.05G (+0.70%)
t3code-server off 3.42s → 3.47s (+1.5%) 2038 → 2037 MiB 83.50G → 83.49G (−0.00%)
t3code-server on 3.87s → 3.87s 2049 → 2026 MiB 88.08G → 89.04G (+1.08%)
vscode off 5.59s → 5.65s (+1.1%) 3274 → 3249 MiB 193.02G → 191.79G (−0.63%)
vscode on 5.95s → 6.27s (+5.4%) 3355 → 3345 MiB 203.60G → 207.12G (+1.73%)
  • Without --type-check: the output is byte-identical, and wall time, peak RSS and instructions are within noise.
  • With --type-check: there is a small cost, about 1–2% more instructions on the larger projects. On vscode, an earlier 2-pair round measured +0.8% instructions and +2.4% wall time, against +1.7% and +5.4% here, so the wall-time number is noisy. Peak RSS does not change.
  • Not measured: xstate-main.

Where the --type-check cost goes

I measured instructions and cycles separately for the type-check part and the rules part of each file. This was single-threaded on vscode with --type-check, two runs each, using temporary proc_pid_rusage probes that are not in this PR.

main (check, then rules, per file) This PR (check all, then rules)
Checker types / instantiations created 3,329,235 / 3,906,226 +4 / +15
Type-check instructions 70.4G 70.7G (+0.4%)
Rules instructions 110.5G 112.9G (+2.1%)
Rules cycles 32.5G 37.2G (+14%)

The checker does the same work, and type checking costs the same. The rules phase is slower for two reasons:

  • Flow memo hits are lost (most of the cost). Rules on a file used to run right after that file was checked, so their flow queries hit flowmemo.rs. Now every later file has been checked first, and those entries are no longer usable, so the rules re-walk the flow graph.
    • With the memo off (TSRS_FLOW_MEMO=0), the instruction gap disappears: 122.5G vs 122.1G.
    • A table 256× bigger (TSRS_FLOW_MEMO_BITS=20) keeps the gap at +3.1G, so entries are being invalidated rather than evicted.
    • The likely cause is that entries which read the flow type cache are valid only while its epoch is current. Checking other files advances that epoch whenever a cached type is replaced. Rejected hits were not counted directly.
  • Caches are colder (the rest). With the memo off, instructions are equal but rules cycles are still about 4% higher. A file's AST and checker data are no longer in the CPU cache when its rules run.

Making the memo's invalidation finer-grained could recover most of this, but that is a separate checker change.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:53

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T13:54:41.881458Z 6f8ab3e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing fix/lint-type-check-before-rules (6f8ab3e) with main (5d07edc)

Open in CodSpeed

Footnotes

  1. 8 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. ↩

@camc314
camc314 force-pushed the fix/lint-type-check-before-rules branch from 65fbbe8 to 6f8ab3e Compare November 10, 2026 14:18
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Performance change vs main

Workflow run · main 5d07edc11dfc → PR merge f64086fa31b1 (head 6f8ab3e6b436)

Clef gate: Running benchmarks because the decision was unavailable (crates/tsrs_lint/src/engine.rs: patch exceeds the Clef context limit (5766 bytes)).

Release builds in fast mode (TSRS_FAST=1) with Hyperfine 2 hardware counters. After warming each binary, alternating main/PR pairs measure wall time at both the fast preset's default checker count and with --singleThreaded, with ten pairs per configuration by default. Instructions come from the single-threaded runs; peak RSS comes from the default-count runs.
Incremental runs start with fresh build info before every invocation; check runs disable incremental compilation.

Project Mode Single-thread wall time Δ Single-thread instructions Δ Default wall time Δ Default peak RSS Δ
vscode check -1.3% -0.001% -0.1% -0.2%
vscode incremental 0.0% 0.000% -4.0% 0.0%
xstate-main check -1.4% 0.000% -2.7% 0.0%
xstate-main incremental +4.1% -0.002% +0.2% -0.7%
webpack check +1.1% -0.002% +1.1% +0.2%
webpack incremental +2.1% +0.003% +6.0% 0.0%
mui-docs check -2.6% -0.004% +0.9% -0.1%
mui-docs incremental -1.2% -0.014% -1.7% -0.2%
Compiler check -0.8% 0.000% +2.6% -0.4%
Compiler incremental -1.6% -0.001% 0.0% -0.2%
Compiler-Unions check -0.6% 0.000% -1.7% +0.8%
Compiler-Unions incremental +0.1% 0.000% +3.4% +0.4%
cal-diy check +0.1% +0.003% -0.9% -0.2%
cal-diy incremental +0.9% +0.002% -3.7% 0.0%
formbricks-web check -3.1% -0.001% +0.2% -0.2%
formbricks-web incremental -1.7% +0.002% +1.3% +0.2%
supabase-studio check +2.8% -0.001% +1.4% 0.0%
supabase-studio incremental +0.7% +0.004% +0.9% -0.1%
t3code-server check +2.8% -0.002% -0.1% 0.0%
t3code-server incremental +0.4% -0.004% +1.2% 0.0%
mikro-orm check -3.7% +0.002% +2.3% -0.8%
mikro-orm incremental +1.8% +0.001% +1.6% 0.0%
next-packages-next check +0.4% -0.001% -4.7% +0.5%
next-packages-next incremental -0.8% 0.000% +2.2% +0.1%
next-root check -0.8% +0.002% -3.2% +0.4%
next-root incremental +0.2% 0.000% -0.2% 0.0%
storybook check -3.0% 0.000% -0.4% -0.4%
storybook incremental -2.7% +0.008% -1.4% -0.3%
nuxt check +4.4% -0.002% -0.8% -0.5%
nuxt incremental +1.6% +0.001% -1.1% -0.2%
playwright check -1.6% -0.001% -1.7% +0.3%
playwright incremental -0.4% -0.001% +0.3% +0.3%
drizzle-orm check -3.3% +0.006% +3.0% -0.1%
drizzle-orm incremental 0.0% -0.005% -4.2% +0.1%
typeorm check -0.8% 0.000% -1.1% +0.4%
typeorm incremental -0.2% +0.001% +6.3% -0.5%
date-fns check -0.8% -0.012% -4.9% -0.1%
date-fns incremental +0.4% +0.003% -4.2% +0.2%

Negative means the PR used less; positive means it used more. Deltas are medians of paired PR/main ratios for wall time and instructions. Single-threaded runs reduce scheduling noise; shared CI machines can still add noise to wall time.

Measured medians (main → PR)
Project Mode Single-thread wall time (s) Single-thread instructions Default wall time (s) Default peak RSS (MiB)
vscode check 9.802 → 9.583 82,406,899,696.5 → 82,406,245,052 1.572 → 1.609 1843.8 → 1840.2
vscode incremental 10.793 → 11.078 84,821,239,321.5 → 84,821,263,878 2.173 → 2.147 2163.3 → 2164.0
xstate-main check 0.575 → 0.576 5,570,903,823 → 5,570,816,549 0.150 → 0.144 241.3 → 241.3
xstate-main incremental 0.983 → 0.997 5,733,680,810 → 5,733,499,082 0.279 → 0.287 244.8 → 243.2
webpack check 1.112 → 1.128 10,900,253,180.5 → 10,899,991,993.5 0.218 → 0.220 403.9 → 404.7
webpack incremental 1.138 → 1.210 11,123,423,649.5 → 11,123,830,231 0.271 → 0.287 403.1 → 403.1
mui-docs check 3.377 → 3.232 33,130,649,842 → 33,125,377,278 1.047 → 1.048 1234.7 → 1233.3
mui-docs incremental 3.512 → 3.380 34,469,297,513 → 34,465,127,753 1.315 → 1.319 1164.3 → 1161.9
Compiler check 0.159 → 0.161 1,776,330,070.5 → 1,776,334,984.5 0.066 → 0.069 77.6 → 77.3
Compiler incremental 0.147 → 0.145 1,789,157,045 → 1,789,141,966.5 0.070 → 0.069 79.6 → 79.5
Compiler-Unions check 0.208 → 0.204 3,054,452,270 → 3,054,459,220 0.103 → 0.102 81.0 → 81.6
Compiler-Unions incremental 0.205 → 0.206 3,066,297,401.5 → 3,066,291,858.5 0.094 → 0.098 84.8 → 85.1
cal-diy check 2.878 → 2.882 28,973,790,657 → 28,974,444,515.5 0.858 → 0.851 1361.3 → 1359.1
cal-diy incremental 3.425 → 3.487 30,593,488,333.5 → 30,593,846,240.5 1.189 → 1.127 1270.7 → 1271.3
formbricks-web check 4.275 → 4.207 37,110,477,462 → 37,110,426,925 1.189 → 1.215 1584.6 → 1581.8
formbricks-web incremental 4.972 → 4.933 39,709,249,397.5 → 39,709,442,958 1.212 → 1.234 1626.1 → 1629.1
supabase-studio check 4.514 → 4.401 40,840,530,927.5 → 40,841,623,647.5 1.113 → 1.119 1314.5 → 1314.1
supabase-studio incremental 5.106 → 5.160 43,789,691,938.5 → 43,791,818,290.5 1.324 → 1.338 1368.9 → 1367.7
t3code-server check 4.211 → 4.337 41,107,803,418 → 41,107,394,404 1.663 → 1.667 1455.8 → 1455.4
t3code-server incremental 3.823 → 3.914 41,631,694,745.5 → 41,630,447,031 1.402 → 1.412 1309.2 → 1309.5
mikro-orm check 5.470 → 5.238 44,562,858,837 → 44,563,630,379.5 1.197 → 1.226 1291.7 → 1281.6
mikro-orm incremental 5.074 → 5.062 44,875,320,928.5 → 44,875,374,324 1.215 → 1.225 1260.9 → 1260.8
next-packages-next check 2.054 → 2.059 17,410,244,562.5 → 17,409,999,745.5 0.521 → 0.481 551.5 → 554.1
next-packages-next incremental 1.816 → 1.801 17,735,910,391.5 → 17,735,823,153.5 0.499 → 0.508 564.0 → 564.7
next-root check 1.768 → 1.562 13,969,237,156.5 → 13,969,451,109 0.704 → 0.700 432.6 → 434.6
next-root incremental 1.289 → 1.286 14,431,015,572 → 14,431,212,943.5 0.324 → 0.324 474.4 → 474.6
storybook check 1.043 → 0.997 8,875,476,122.5 → 8,875,521,588 0.264 → 0.283 398.1 → 396.4
storybook incremental 0.853 → 0.840 9,200,325,560 → 9,200,703,196.5 0.260 → 0.252 377.2 → 376.1
nuxt check 0.978 → 1.015 8,506,888,288.5 → 8,506,922,024.5 0.280 → 0.278 392.1 → 390.1
nuxt incremental 1.028 → 1.045 8,909,459,801 → 8,909,227,915 0.248 → 0.248 393.7 → 392.8
playwright check 0.797 → 0.781 7,408,363,568 → 7,408,271,915 0.193 → 0.189 362.0 → 363.2
playwright incremental 0.784 → 0.789 7,581,338,899 → 7,581,580,612 0.200 → 0.205 339.5 → 340.5
drizzle-orm check 0.985 → 0.960 5,952,553,686 → 5,952,737,573.5 0.312 → 0.316 381.7 → 381.3
drizzle-orm incremental 0.770 → 0.768 6,124,333,470.5 → 6,124,242,576 0.265 → 0.262 346.5 → 346.8
typeorm check 0.671 → 0.676 6,400,120,358 → 6,400,121,577.5 0.139 → 0.139 226.6 → 227.5
typeorm incremental 0.681 → 0.692 6,777,445,912.5 → 6,777,474,183 0.203 → 0.218 234.5 → 233.2
date-fns check 0.283 → 0.283 3,357,439,013.5 → 3,356,880,848.5 0.089 → 0.085 153.9 → 153.8
date-fns incremental 0.335 → 0.338 3,594,151,738 → 3,594,271,901.5 0.168 → 0.163 163.1 → 163.5

tsrs-lint

Release tsrs-lint linting each project's source files with all 61 rules. After a warmup run of each binary, alternating main/PR pairs (10 per mode) measure wall time, CPU time and peak RSS with TSRS_FAST unset and with TSRS_FAST=1.

Project Mode Wall time Δ CPU time Δ Peak RSS Δ Diagnostics (main → PR)
webpack default +0.3% +0.9% -0.4% 37258, identical
webpack TSRS_FAST=1 -0.1% +0.3% -0.3% 37258, identical
drizzle-orm default +1.1% +1.1% -0.1% 7057, identical
drizzle-orm TSRS_FAST=1 +1.3% +0.7% -0.1% 7057, identical
xstate-main default -0.4% +0.1% +0.7% 6489, identical
xstate-main TSRS_FAST=1 -0.5% +0.2% 0.0% 6489, identical

Negative means the PR used less. Wall and CPU time deltas are medians of paired PR/main ratios; peak RSS compares medians.

Measured lint medians (main → PR)
Project Mode Wall time (s) CPU time (s) Peak RSS (MiB)
webpack default 0.540 → 0.543 1.736 → 1.756 409.0 → 407.3
webpack TSRS_FAST=1 0.356 → 0.358 1.864 → 1.875 435.3 → 434.1
drizzle-orm default 0.355 → 0.358 1.168 → 1.176 431.6 → 431.2
drizzle-orm TSRS_FAST=1 0.214 → 0.215 1.156 → 1.166 392.8 → 392.3
xstate-main default 0.455 → 0.453 1.292 → 1.296 320.7 → 322.9
xstate-main TSRS_FAST=1 0.375 → 0.375 1.330 → 1.331 310.4 → 310.5

@camc314
camc314 added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 491e7e4 Nov 10, 2026
110 of 141 checks passed
@camc314
camc314 deleted the fix/lint-type-check-before-rules branch November 10, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

tsrs-lint --type-check reports a TS2590 on the tsconfig that a rule's type query caused (no-unsafe-enum-assignment); tsrs --noEmit reports none

2 participants