Repository navigation
Speed up short-lived checker caches - #64871
Open
Jake Bailey (jakebailey) wants to merge 3 commits into
Open
Jake Bailey (jakebailey) wants to merge 3 commits into
Jake Bailey (jakebailey) wants to merge 3 commits into
Conversation
Every instantiation under an active mapper built and hashed a 128-bit
key before probing the mapper's cache, even when the mapper had just
been pushed and its cache was necessarily empty. Most keys carry no
alias, so the type ID alone identifies the entry.
Measured with --checkers 4 (n=8):
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
Tsc/bluesky 2.756 ± 3% 2.742 ± 3% ~ (p=0.366 n=8)
Tsc/sentry 11.20 ± 3% 11.19 ± 4% ~ (p=0.742 n=8)
Tsc/t3code-server 10.84 ± 3% 10.72 ± 2% -1.10% (p=0.038 n=8)
geomean 6.942 6.902 -0.58%
│ before.txt │ after.txt │
│ rss-B │ rss-B vs base │
Tsc/bluesky 1.190Gi ± 1% 1.182Gi ± 3% ~ (p=0.798 n=8)
Tsc/sentry 3.438Gi ± 7% 3.518Gi ± 6% ~ (p=0.645 n=8)
Tsc/t3code-server 2.852Gi ± 2% 2.879Gi ± 3% ~ (p=0.721 n=8)
geomean 2.268Gi 2.287Gi +0.86%
│ before.txt │ after.txt │
│ heap-B │ heap-B vs base │
Tsc/bluesky 934.9Mi ± 0% 934.8Mi ± 0% ~ (p=0.959 n=8)
Tsc/sentry 2.607Gi ± 0% 2.609Gi ± 0% ~ (p=0.382 n=8)
Tsc/t3code-server 2.303Gi ± 0% 2.302Gi ± 0% ~ (p=0.083 n=8)
geomean 1.763Gi 1.763Gi -0.00%
The instantiation cache of an active mapper is cleared every time the
mapper is popped. Clearing a Go map takes time proportional to its
capacity, which stays large once a map has grown, so instantiating
under a mapper whose cache once held many entries paid for that size
on every pop.
The caches are now small open-addressing tables whose entries record
the generation they were written in; clearing starts a new generation.
They also hash keys with a multiply rather than a full 128-bit hash.
Measured with --checkers 4 (n=8):
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
Tsc/bluesky 2.716 ± 2% 2.708 ± 5% ~ (p=0.279 n=8)
Tsc/sentry 11.14 ± 1% 11.01 ± 1% ~ (p=0.130 n=8)
Tsc/t3code-server 9.997 ± 3% 9.462 ± 2% -5.35% (p=0.000 n=8)
geomean 6.712 6.559 -2.29%
│ before.txt │ after.txt │
│ rss-B │ rss-B vs base │
Tsc/bluesky 1.191Gi ± 1% 1.180Gi ± 1% -0.95% (p=0.028 n=8)
Tsc/sentry 3.495Gi ± 5% 3.399Gi ± 7% ~ (p=0.878 n=8)
Tsc/t3code-server 2.855Gi ± 5% 2.844Gi ± 3% ~ (p=0.798 n=8)
geomean 2.282Gi 2.251Gi -1.36%
│ before.txt │ after.txt │
│ heap-B │ heap-B vs base │
Tsc/bluesky 935.2Mi ± 0% 935.1Mi ± 0% ~ (p=0.279 n=8)
Tsc/sentry 2.611Gi ± 0% 2.611Gi ± 0% ~ (p=0.798 n=8)
Tsc/t3code-server 2.305Gi ± 0% 2.305Gi ± 0% ~ (p=0.505 n=8)
geomean 1.765Gi 1.765Gi -0.00%
Inference states are pooled, and each one's visited map is cleared when
it is returned to the pool. Like the mapper caches, a pooled map that
once grew large paid for its capacity on every clear, and every probe
paid for hashing a struct key.
Measured with --checkers 4:
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
Tsc/bluesky 2.747 ± 2% 2.725 ± 3% ~ (p=0.645 n=8)
Tsc/sentry 11.20 ± 2% 11.01 ± 2% ~ (p=0.239 n=16)
Tsc/t3code-server 9.504 ± 1% 9.287 ± 1% -2.28% (p=0.000 n=16)
geomean 6.637 6.532 -1.58%
│ before.txt │ after.txt │
│ rss-B │ rss-B vs base │
Tsc/bluesky 1.190Gi ± 2% 1.183Gi ± 1% ~ (p=0.382 n=8)
Tsc/sentry 3.473Gi ± 5% 3.366Gi ± 3% ~ (p=0.171 n=16)
Tsc/t3code-server 2.915Gi ± 3% 2.839Gi ± 3% ~ (p=0.515 n=16)
geomean 2.293Gi 2.244Gi -2.11%
│ before.txt │ after.txt │
│ heap-B │ heap-B vs base │
Tsc/bluesky 935.3Mi ± 0% 935.3Mi ± 0% ~ (p=0.959 n=8)
Tsc/sentry 2.611Gi ± 0% 2.612Gi ± 0% ~ (p=0.128 n=16)
Tsc/t3code-server 2.305Gi ± 0% 2.306Gi ± 0% ~ (p=0.323 n=16)
geomean 1.765Gi 1.765Gi +0.02%
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused optimization preserves cache behavior, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Optimizes the compiler’s active mapper instantiation cache to reduce unnecessary key hashing.
Changes:
- Skips cache lookup and key construction for newly pushed mappers.
- Uses type IDs directly for alias-free keys, retaining hashing for aliased types.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Streamlines mapper cache lookups and adds optimized key generation. |
Review effort: Balanced
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Member
Author
|
TypeScript Bot (@typescript-bot) perf test |
Contributor
|
Starting jobs; this comment will be updated as builds start and complete.
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every instantiation under an active mapper built and hashed a 128-bit key before probing the mapper's cache, even when the mapper had just been pushed and its cache was necessarily empty. Most keys carry no alias, so the type ID alone identifies the entry.
Active mapper caches and inference visited sets are also cleared far more often than they are filled. Clearing a Go map costs time proportional to its capacity, which stays at its high-water mark, so each pop of an active mapper and each reuse of an inference state paid for the largest cache seen so far. Both now use a small table keyed by the same 128-bit keys that clears in constant time by bumping a generation counter instead of touching every slot.
The measurements below are for the key hashing change alone; the per-commit measurements for the constant-time clears are in their commit messages.
Measured with --checkers 4 (n=8):