Title: Performance issue on updating Babel monorepo typescript from 4.7.4 to 4.8.2 · Issue #50515 · microsoft/TypeScript · GitHub
Open Graph Title: Performance issue on updating Babel monorepo typescript from 4.7.4 to 4.8.2 · Issue #50515 · microsoft/TypeScript
X Title: Performance issue on updating Babel monorepo typescript from 4.7.4 to 4.8.2 · Issue #50515 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms out of memory Symbols Types 4.8 regression 🕗 Version & Regression Information This is a crash This changed between versions 4.8.0-dev.20220527 and 4.8.0-dev.20220528 💻 Code // We can quickly address your report ...
Open Graph Description: Bug Report 🔎 Search Terms out of memory Symbols Types 4.8 regression 🕗 Version & Regression Information This is a crash This changed between versions 4.8.0-dev.20220527 and 4.8.0-dev.20220528 💻 Cod...
X Description: Bug Report 🔎 Search Terms out of memory Symbols Types 4.8 regression 🕗 Version & Regression Information This is a crash This changed between versions 4.8.0-dev.20220527 and 4.8.0-dev.20220528 💻...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50515
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Performance issue on updating Babel monorepo typescript from 4.7.4 to 4.8.2","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\nout of memory\r\nSymbols\r\nTypes\r\n4.8 regression\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This is a crash\r\n- This changed between versions `4.8.0-dev.20220527` and `4.8.0-dev.20220528`\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\n// We can quickly address your report if:\r\n// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!\r\n// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.\r\n// - The incorrectness of the behavior is readily apparent from reading the sample.\r\n// Reports are slower to investigate if:\r\n// - We have to pare too much extraneous code.\r\n// - We have to clone a large repo and validate that the problem isn't elsewhere.\r\n// - The sample is confusing or doesn't clearly demonstrate what's wrong.\r\n```\r\n❗ It is a large repo. But we have narrowed down the suspicious code paths. See the \"Context\" section.\r\n\r\nCheckout https://github.com/JLHwung/babel/tree/ts-4-8-regression\r\n\r\nRun `yarn && yarn tsc --extendedDiagnostics --incremental false`\r\n\r\n### 🙁 Actual behavior\r\n\r\n\u003c!-- What happened, and why it was wrong -->\r\n4.8.0-dev.20220528:\r\n```\r\nFiles: 714\r\nLines of Library: 27991\r\nLines of Definitions: 48613\r\nLines of TypeScript: 109741\r\nLines of JavaScript: 0\r\nLines of JSON: 4198\r\nLines of Other: 0\r\nNodes of Library: 119423\r\nNodes of Definitions: 127849\r\nNodes of TypeScript: 416263\r\nNodes of JavaScript: 0\r\nNodes of JSON: 11813\r\nNodes of Other: 0\r\nIdentifiers: 230685\r\nSymbols: 3072081\r\nTypes: 1627331\r\nInstantiations: 42109836\r\nMemory used: 4019580K\r\nAssignability cache size: 266387\r\nIdentity cache size: 16941\r\nSubtype cache size: 99137\r\nStrict subtype cache size: 9238\r\nI/O Read time: 0.03s\r\nParse time: 0.49s\r\nResolveModule time: 0.06s\r\nResolveTypeReference time: 0.00s\r\nProgram time: 0.63s\r\nBind time: 0.30s\r\nCheck time: 67.33s\r\ntransformTime time: 4.21s\r\nSource Map time: 0.12s\r\ncommentTime time: 0.14s\r\nI/O Write time: 0.10s\r\nprintTime time: 5.26s\r\nEmit time: 5.26s\r\nTotal time: 73.53s\r\n```\r\n\r\ntsc 4.7.4\r\n```\r\nFiles: 714\r\nLines of Library: 27958\r\nLines of Definitions: 48613\r\nLines of TypeScript: 109737\r\nLines of JavaScript: 0\r\nLines of JSON: 4198\r\nLines of Other: 0\r\nNodes of Library: 119371\r\nNodes of Definitions: 127849\r\nNodes of TypeScript: 416262\r\nNodes of JavaScript: 0\r\nNodes of JSON: 11813\r\nNodes of Other: 0\r\nIdentifiers: 230675\r\nSymbols: 959380\r\nTypes: 380554\r\nInstantiations: 42135598\r\nMemory used: 1102821K\r\nAssignability cache size: 262472\r\nIdentity cache size: 16941\r\nSubtype cache size: 100724\r\nStrict subtype cache size: 8524\r\nI/O Read time: 0.02s\r\nParse time: 0.49s\r\nResolveModule time: 0.05s\r\nResolveTypeReference time: 0.00s\r\nProgram time: 0.62s\r\nBind time: 0.30s\r\nCheck time: 15.77s\r\ntransformTime time: 0.97s\r\nSource Map time: 0.04s\r\ncommentTime time: 0.06s\r\nI/O Write time: 0.09s\r\nprintTime time: 1.50s\r\nEmit time: 1.50s\r\nTotal time: 18.18s\r\n```\r\n\r\ntsc 4.8 increases memory usage from 1GB to 4GB, thus performance is worsen from 18s to 73s. The increased memory usage [fails our CI](https://github.com/babel/babel/runs/8027952190?check_suite_focus=true) by OOM error. The \"Symbols\" and \"Types\" significantly increased.\r\n\r\n### 🙂 Expected behavior\r\n\r\nMemory usage should not be quadrupled.\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n\r\n### 👓 Context\r\n\r\nThe issue surfaced when we upgrade from 4.7.4 to 4.8.2: https://github.com/babel/babel/pull/14880\r\nLater @liuxingbaoyu managed to narrow down the root cause:\r\n\r\n```ts\r\nclass NodePath\u003cT extends t.Node = t.Node> {\r\n getScope(scope: Scope): Scope {\r\n return this.isScope() ? new Scope(this) : scope;\r\n }\r\n}\r\n```\r\nhttps://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-traverse/src/path/index.ts#L111-L113\r\n\r\nwhere `Scope` accepts `NodePath\u003ct.Pattern | t.Scopeable>`. `t.Pattern | t.Scopeable` is subset of `t.Node`, which is a union of 252 AST types. (https://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-types/src/ast-types/generated/index.ts#L50)\r\n\r\nThe `isScope` is defined as\r\n```ts\r\ninterface VirtualTypeNodePathValidators\r\n isScope\u003cT extends t.Node>(\r\n this: NodePath\u003cT>,\r\n opts?: object,\r\n ): this is NodePath\u003cT & VirtualTypeAliases[\"Scope\"]>;\r\n}\r\n```\r\nhttps://github.com/babel/babel/blob/6c5ebd12fa3a3e594f5dc8dab2b4f44e153f5976/packages/babel-traverse/src/path/lib/virtual-types-validator.ts#L72\r\n\r\nwhere `VirtualTypeAliases[\"Scope\"]` resolves to `t.Pattern | t.Scopeable`.\r\n\r\nIt seems to me `tsc` spends quite a bit of effort to check `new Scope(this)` is valid behind the `this.isScope` check. We can workaround the issue by casting `this` to `NodePath\u003ct.Pattern | t.Scopeable>`:\r\n\r\n```diff\r\nClass NodePath\u003cT extends t.Node = t.Node> {\r\n getScope(scope: Scope): Scope {\r\n+++ return this.isScope() ? new Scope(this as NodePath\u003ct.Pattern | t.Scopeable>) : scope;\r\n--- return this.isScope() ? new Scope(this) : scope;\r\n }\r\n}\r\n```\r\n\r\nYet I expect `tsc` infers that `NodePath\u003cT & VirtualTypeAliases[\"Scope\"]>` must subset `NodePath\u003ct.Pattern | t.Scopeable>` and thus `new Scope` is valid without that much efforts.\r\n\r\nI did a rough bisect and the issue was first introduced in `4.8.0-dev.20220528`. The regression might be introduced in https://github.com/microsoft/TypeScript/pull/49119.","author":{"url":"https://github.com/JLHwung","@type":"Person","name":"JLHwung"},"datePublished":"2022-08-29T14:26:41Z","url":"https://github.com/microsoft/TypeScript/issues/50515"}
| 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:05b1eeab-9867-b92e-b531-bd2222659036 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 925C:2AAD2E:274456E:3470120:6B01B125 |
| html-safe-nonce | 7154364ba9dd1e49f86cd256bd1c9e3e5f9a8a7d02e15f2fc3c41236f5643e9e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjVDOjJBQUQyRToyNzQ0NTZFOjM0NzAxMjA6NkIwMUIxMjUiLCJ2aXNpdG9yX2lkIjoiNDcyMTYzMjE5MjI0ODI2Mjk0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cac55678aa9802b410f32a90bb95662683559acdc31408cfb3e7a470d1ac0824 |
| hovercard-subject-tag | issue:1354398239 |
| 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/50515/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc860f0bd5ca9180e5e0a661bdd1909b3fe4737e37eab4a636c32d5b6bbea189/microsoft/TypeScript/issues/50515 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc860f0bd5ca9180e5e0a661bdd1909b3fe4737e37eab4a636c32d5b6bbea189/microsoft/TypeScript/issues/50515 |
| og:image:alt | Bug Report 🔎 Search Terms out of memory Symbols Types 4.8 regression 🕗 Version & Regression Information This is a crash This changed between versions 4.8.0-dev.20220527 and 4.8.0-dev.20220528 💻 Cod... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JLHwung |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width