-
Notifications
You must be signed in to change notification settings - Fork 382
perf: cache HTTP operation resolution at the program level #11318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iscai-msft
merged 25 commits into
microsoft:main
from
iscai-msft:iscai-msft-linter-perf-improvements
Jul 28, 2026
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8e62425
feat: add program.currentStage and program.useCache for stage-aware c…
ab122d7
fix: only cache from linting stage onward (not during validating)
11aad48
fix: restrict HTTP operation cache to emitting stage only
3c85835
fix: add missing devDependencies for build ordering in http-canonical…
55f7d41
feat: add program.currentStage and program.useCache for stage-aware c…
dc508ff
test: minimal change to isolate Azure CI failure cause
2cb3820
perf: cache getHttpOperation during emitting stage
ae04583
fix: revert getHttpOperation caching, add ARM singleton repro tests
4289ed9
perf: cache getHttpOperation results during linting and emitting
b5a17a2
chore: remove unrelated changes
6bdf507
test: add getHttpOperation caching tests
f7a6ea8
fix: lint warnings and add @typespec/http changeset
dde38a3
Merge branch 'main' into iscai-msft-linter-perf-improvements
iscai-msft 4136d89
perf: use module-level WeakMap cache for getHttpOperation (emitting o…
f89438a
Revert "perf: use module-level WeakMap cache for getHttpOperation (em…
94f770a
feat: invalidate useCache on type graph mutation
2ce428d
refactor: move useCache/invalidateCaches to experimental API
0bfe54b
refactor: remove currentStage from public Program interface
b4c6bd9
chore: remove accidental vitest build artifacts from PR
96ec6f1
refactor: surgical cache invalidation on mutation
f4ee80c
refactor: make invalidateCaches require types parameter
74951d4
refactor: remove invalidateCaches and bypass cache for unfinished types
6dfdab1
Merge remote-tracking branch 'upstream/main' into iscai-msft-linter-p…
1813e88
chore: merge upstream main and format
d32a767
refactor: move useCache logic from program.ts to cache.ts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/compiler" | ||
| --- | ||
|
|
||
| Add `currentStage` property and `useCache` method to `Program` for stage-aware caching. `currentStage` tracks the compilation pipeline stage (parsing → checking → validating → linting → emitting), and `useCache` provides a generic caching mechanism that libraries can use to avoid redundant computation during later stages. |
7 changes: 7 additions & 0 deletions
7
.chronus/changes/http-operation-cache-http-2026-7-22-19-25-0.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/http" | ||
| --- | ||
|
|
||
| Cache `getHttpOperation` results during linting and emitting stages using `program.useCache()`. This eliminates redundant route resolution when multiple linter rules inspect the same operations, improving linter performance on large specs. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { Program } from "../core/program.js"; | ||
| import type { Type } from "../core/types.js"; | ||
|
|
||
| /** | ||
| * Get a cached value for the given key, computing it if not already cached. | ||
| * Caching is only active from the "validating" stage onward and only for | ||
| * finished types. During "parsing" and "checking", decorators are still being | ||
| * applied. Unfinished types (during decorator application or inside mutators) | ||
| * are never cached because the type graph may not yet be in a stable state. | ||
| * | ||
| * @param program The program instance. | ||
| * @param key A unique symbol identifying this cache namespace. | ||
| * @param type The type to use as the cache key within this namespace. | ||
| * @param compute A function that computes the value if not cached. | ||
| * @returns The cached or freshly computed value. | ||
| * | ||
| * @experimental | ||
| */ | ||
| export function useCache<T>(program: Program, key: symbol, type: Type, compute: () => T): T { | ||
| const stage = program.currentStage; | ||
| // Only cache from "validating" onward. During "parsing" and "checking", | ||
| // decorators are still being applied and may not have finished setting up | ||
| // route options, filters, or other state that affects resolution. By | ||
| // "validating" all decorators have completed and types are fully resolved. | ||
| if (stage !== "validating" && stage !== "linting" && stage !== "emitting") { | ||
| return compute(); | ||
| } | ||
| // Don't cache results for unfinished types. Types are unfinished during | ||
| // decorator application (including late template instantiation in the | ||
| // emitting stage) and inside mutators. Caching at those points risks | ||
| // storing results computed against an incomplete type graph. | ||
| if (!type.isFinished) { | ||
| return compute(); | ||
| } | ||
| const map = program.stateMap(key); | ||
| const existing = map.get(type); | ||
| if (existing !== undefined) { | ||
| return existing as T; | ||
| } | ||
| const value = compute(); | ||
| map.set(type, value); | ||
| return value; | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.