We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
"optional chaining", "slow compilation", "performance"
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250225#code/C4TwDgpgBAchDOwIBMoF4oG8BQU9QGMALASwBtkAnCAOwC5YElkBtAXQBpd8A3AQzIBXCAxqCAtgCMIlbAF9s2AgHsaiKPAh9KxKAziIU6LNzzFyVWg3Zd8UfkJFQArPMUq1wKH2ObtxADpzCmoaAH4AgDMSGmQASViIAA8AChSaAEp0AD4oGgCHYXQMAEYMgG4lVXVJXy0dIiDSENoWPjYI4MtwqJj4xNT0rLRc-MLoNAwAJgqqz0I6-0au0LaOpotVyXWV2gjo2ITkZLTMnLyCgSLJqABmWY91VAw-Bo2WmjXO5u6Wbe-Nq0CDsfqFeocBqdhqNLo5ilAACwPapeCYaeqBXafdoAj5-EGAz7A3G-ZAEj7g-rHQZnEYXcbw5zI+aRRZvLFfd6-f5c1bE3mtMkk1YQcndSlHE5Dc5jK4TDAANmZ6gA5mzMaDWjiBZ8eRz+RyhTqWKLha1ImKwQcqVLaTCGTcAOyzObwZRkCABMjKFUpADkABFVBA-RUgA
type Nested = { children: Nested[], value: number } const search : Nested = { children: [], value: 5 } const a = search.children?.findIndex((n) => n.value == 1); const b = search.children[a]?.children?.findIndex((n) => n.value == 2); const c = search.children[a]?.children[b]?.children?.findIndex((n) => n.value == 3); const d = search.children[a]?.children[b]?.children[c]?.children.findIndex((n) => n.value == 4); const e = search.children[a]?.children[b]?.children[c]?.children[d]?.children.findIndex((n) => n.value == 5); const f = search.children[a]?.children[b]?.children[c]?.children[d]?.children[e]?.children.findIndex((n) => n.value == 6); const g = search.children[a]?.children[b]?.children[c]?.children[d]?.children[e]?.children[f]?.children.findIndex((n) => n.value == 7); console.log('Done');
Compilation time gets increasingly slow as more nested accesses using optional chaining are added.
Timing on my machine:
Compilation time remains about the same or increases linearly.
Originally found while diagnosing slow compile times in a project dealing with searches through a potentially nested API response.
Output of tsc --diagnostics:
tsc --diagnostics
Files: 58 Lines: 10638 Identifiers: 8659 Symbols: 7911 Types: 3124 Instantiations: 1150 Memory used: 56818K I/O read: 0.02s I/O write: 0.00s Parse time: 0.12s Bind time: 0.04s Check time: 165.76s Emit time: 56.28s Total time: 222.20s
As a workaround, refactoring to assign the repeated index lookups to intermediate variables resolves the performance issue.
The text was updated successfully, but these errors were encountered:
rbuckton
No branches or pull requests
🔎 Search Terms
"optional chaining", "slow compilation", "performance"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250225#code/C4TwDgpgBAchDOwIBMoF4oG8BQU9QGMALASwBtkAnCAOwC5YElkBtAXQBpd8A3AQzIBXCAxqCAtgCMIlbAF9s2AgHsaiKPAh9KxKAziIU6LNzzFyVWg3Zd8UfkJFQArPMUq1wKH2ObtxADpzCmoaAH4AgDMSGmQASViIAA8AChSaAEp0AD4oGgCHYXQMAEYMgG4lVXVJXy0dIiDSENoWPjYI4MtwqJj4xNT0rLRc-MLoNAwAJgqqz0I6-0au0LaOpotVyXWV2gjo2ITkZLTMnLyCgSLJqABmWY91VAw-Bo2WmjXO5u6Wbe-Nq0CDsfqFeocBqdhqNLo5ilAACwPapeCYaeqBXafdoAj5-EGAz7A3G-ZAEj7g-rHQZnEYXcbw5zI+aRRZvLFfd6-f5c1bE3mtMkk1YQcndSlHE5Dc5jK4TDAANmZ6gA5mzMaDWjiBZ8eRz+RyhTqWKLha1ImKwQcqVLaTCGTcAOyzObwZRkCABMjKFUpADkABFVBA-RUgA
💻 Code
🙁 Actual behavior
Compilation time gets increasingly slow as more nested accesses using optional chaining are added.
Timing on my machine:
🙂 Expected behavior
Compilation time remains about the same or increases linearly.
Additional information about the issue
Originally found while diagnosing slow compile times in a project dealing with searches through a potentially nested API response.
Output of
tsc --diagnostics
:As a workaround, refactoring to assign the repeated index lookups to intermediate variables resolves the performance issue.
The text was updated successfully, but these errors were encountered: