Title: Declaration diagnostics allocate a diagnostic selector closure for every declaration visited · Issue #64720 · microsoft/TypeScript · GitHub
Open Graph Title: Declaration diagnostics allocate a diagnostic selector closure for every declaration visited · Issue #64720 · microsoft/TypeScript
X Title: Declaration diagnostics allocate a diagnostic selector closure for every declaration visited · Issue #64720 · microsoft/TypeScript
Description: 🔎 Search Terms declaration emit performance, declaration diagnostics, allocations, setupDiagnosticContext, createGetSymbolAccessibilityDiagnosticForNode, noEmit declaration 🕗 Version & Regression Information Observed on main (7.1.0-dev, ...
Open Graph Description: 🔎 Search Terms declaration emit performance, declaration diagnostics, allocations, setupDiagnosticContext, createGetSymbolAccessibilityDiagnosticForNode, noEmit declaration 🕗 Version & Regression I...
X Description: 🔎 Search Terms declaration emit performance, declaration diagnostics, allocations, setupDiagnosticContext, createGetSymbolAccessibilityDiagnosticForNode, noEmit declaration 🕗 Version & Regressi...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/64720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Declaration diagnostics allocate a diagnostic selector closure for every declaration visited","articleBody":"### 🔎 Search Terms\n\ndeclaration emit performance, declaration diagnostics, allocations, setupDiagnosticContext, createGetSymbolAccessibilityDiagnosticForNode, noEmit declaration\n\n### 🕗 Version & Regression Information\n\n- Observed on `main` (7.1.0-dev, aa8149273b, 2026-10-09).\n\n### ⏯ Playground Link\n\nNot reproducible in the playground; it needs a generated project. Generator below.\n\n### 💻 Code\n\n`node gen.mjs && tsgo -p . --extendedDiagnostics`\n\n```js\n// Ordinary files with many exported declarations, checked with `declaration: true` so that declaration\n// diagnostics run the declaration transformer over every declaration.\nimport fs from \"node:fs\";\nconst FILES = 1500, CLASSES_PER_FILE = 6;\nfs.mkdirSync(\"src\", { recursive: true });\nfor (let f = 0; f \u003c FILES; f++) {\n let text = \"\";\n for (let c = 0; c \u003c CLASSES_PER_FILE; c++) {\n const n = `${f}_${c}`;\n text += `export interface Options${n} { name: string; size?: number; tags: readonly string[] }\nexport class Service${n}\u003cT extends object = {}> {\n private readonly items = new Map\u003cstring, T>();\n static readonly kind = \"service${n}\" as const;\n constructor(public readonly options: Options${n}, protected limit = 10) {}\n get count() { return this.items.size; }\n set count(value: number) { this.limit = value; }\n add(key: string, item: T, overwrite = false) { if (overwrite || !this.items.has(key)) this.items.set(key, item); return this; }\n find(predicate: (item: T, key: string) => boolean) { for (const [key, item] of this.items) if (predicate(item, key)) return { key, item }; return undefined; }\n map\u003cU>(fn: (item: T) => U) { return [...this.items.values()].map(fn); }\n}\nexport function create${n}(options: Options${n}) { return new Service${n}(options); }\nexport const defaults${n} = { name: \"${n}\", size: ${c}, tags: [\"a\", \"b\"] as const };\nexport type Item${n} = ReturnType\u003ctypeof create${n}> extends Service${n}\u003cinfer T> ? T : never;\n`;\n }\n fs.writeFileSync(`src/file${f}.ts`, text);\n}\nfs.writeFileSync(\"tsconfig.json\", JSON.stringify({ compilerOptions: { target: \"es2022\", module: \"esnext\", moduleResolution: \"bundler\", strict: true, declaration: true, noEmit: true, types: [], lib: [\"es2022\"] }, include: [\"src\"] }));\n```\n\n### 🙁 Actual behavior\n\n14.5M allocations for a 1,557-file program with no errors.\n\nEvery declaration the declaration transformer visits installs a diagnostic context: `setupDiagnosticContext` calls `createGetSymbolAccessibilityDiagnosticForNode`, which allocates a closure that picks the message to report if a symbol used by the declaration turns out to be inaccessible. It also returns a second closure that restores the previous context. The selector is only invoked when such an error is actually reported, which almost never happens.\n\nThis runs for every emitted declaration file, and under `noEmit` with `declaration` enabled for every file's declaration diagnostics. In an 8.6k-file package of a private monorepo, the two closures were 11% of all allocations of a `--noEmit` check.\n\n### 🙂 Expected behavior\n\nEstablishing a diagnostic context should not allocate; the selector only needs to exist once an error is reported.\n\n### Additional information about the issue\n\nWith the change in the linked PR, the program above makes 8.7M allocations (−40%) and the monorepo check makes 11% fewer. Emitted declarations and diagnostics are unchanged.\n\nThe profiling and the patch were done with Claude Code.\n\n","author":{"url":"https://github.com/gwkline","@type":"Person","name":"gwkline"},"datePublished":"2026-10-10T09:00:31Z","url":"https://github.com/microsoft/TypeScript/issues/64720"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bfed0fdd-5870-5c0a-8c7b-50dc7a881465 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEB2:3F8AB1:1260F6C:177D2AE:6B010AD5 |
| html-safe-nonce | d0cc15f6e4078b8904b32788770ef95f4ea9d3b068a273de03cc6ffaf06b3259 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUIyOjNGOEFCMToxMjYwRjZDOjE3N0QyQUU6NkIwMTBBRDUiLCJ2aXNpdG9yX2lkIjoiNTk3Nzk1Mzk3Nzk0NDMxMjUzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f81c66845b6e7f1f97f76b349f988adfcae56803636a215c9d62559e51119112 |
| hovercard-subject-tag | issue:5789782994 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/64720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bf8f7c4aa0bf485986a294a1853a93ed3a500778ea33e6d889cb56eeb3806689/microsoft/TypeScript/issues/64720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bf8f7c4aa0bf485986a294a1853a93ed3a500778ea33e6d889cb56eeb3806689/microsoft/TypeScript/issues/64720 |
| og:image:alt | 🔎 Search Terms declaration emit performance, declaration diagnostics, allocations, setupDiagnosticContext, createGetSymbolAccessibilityDiagnosticForNode, noEmit declaration 🕗 Version & Regression I... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gwkline |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width