Whole-program pass: 16 s down to under a second on a package with large code tables #111
Loading…
Reference in a new issue
No description provided.
Delete branch "perf-whole-program-pass"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
safe-ts checktook about 16 seconds on an adopter's project, and nearly all of it came from one package of 58 files. An agent is meant to run the checker after every edit, so this defeated the point of the tool. That package now takes under a second.Where the time went
Measured with temporary per-rule timing (none of it is in the commit):
(typeof X)[keyof typeof X]over acodesOf(...)table) it builds about 5,000 type instances and takes about 65 ms.strict-truthinesssites asking whether such a code can be falsy accounted for 12.3 of the 15.6 seconds.The fix
What a type evaluates to is now kept for the rest of the pass and reused, together with the evaluator state it leaves behind.
The cache key holds everything the result depends on: the type's structure, the declaration its name resolves to (so every file importing the same type shares one answer, and a different type with the same name does not), the context, and the per-site settings. It is used only when the evaluator has not evaluated anything yet, so a hit is exactly a re-evaluation without the work. It lives for one check and is never reused across edits.
Result
Whole-program pass on the adopter's project, three runs each:
The other entries are unchanged within noise.
How it was checked
test:stdandtypecheckpass.To know
sentinel-error, which searches every source file of the package as text for each file with candidate functions. Making it cheaper means deciding which files count as callers, so it is not a mechanical change.Created with Claude Opus 5.5 (measurement and implementation) and Claude Fable 5.2 (review, and an independent rerun of the comparison and timings) in Claude Code.
as#113