Title: Add API to (de)serialize parsed Node objects · Issue #26871 · microsoft/TypeScript · GitHub
Open Graph Title: Add API to (de)serialize parsed Node objects · Issue #26871 · microsoft/TypeScript
X Title: Add API to (de)serialize parsed Node objects · Issue #26871 · microsoft/TypeScript
Description: Search Terms Serialization, deserialization, dumping, dump source file, compiler cache Related issues #25658, TypeStrong/ts-loader#825 Suggestion I'd like to suggest to add an API to be able to (de-)serialize any parsed Node or make pars...
Open Graph Description: Search Terms Serialization, deserialization, dumping, dump source file, compiler cache Related issues #25658, TypeStrong/ts-loader#825 Suggestion I'd like to suggest to add an API to be able to (de...
X Description: Search Terms Serialization, deserialization, dumping, dump source file, compiler cache Related issues #25658, TypeStrong/ts-loader#825 Suggestion I'd like to suggest to add an API to be able to...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26871
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add API to (de)serialize parsed Node objects","articleBody":"## Search Terms\r\n\r\nSerialization, deserialization, dumping, dump source file, compiler cache\r\n\r\n## Related issues\r\n\r\n#25658, https://github.com/TypeStrong/ts-loader/issues/825\r\n\r\n## Suggestion\r\n\r\nI'd like to suggest to add an API to be able to (de-)serialize any parsed Node or make parsed AST be easy (de-)serializable by, for example, `JSON.stringify()`.\r\n\r\n## Use Cases\r\n\r\nIt can be used to make cache of parsed source files, which can be used between compilations without parsing unchanged source files again.\r\n\r\nFor example, for our project at the moment we have the following times for compilation:\r\n\r\n```\r\n$ ./node_modules/.bin/tsc --diagnostics --skipLibCheck\r\nFiles: 1767\r\nLines: 226078\r\nNodes: 1036945\r\nIdentifiers: 315470\r\nSymbols: 380158\r\nTypes: 137886\r\nMemory used: 497393K\r\nI/O read: 0.63s\r\nI/O write: 2.09s\r\nParse time: 10.79s\r\nBind time: 2.10s\r\nCheck time: 12.47s\r\nEmit time: 10.72s\r\nTotal time: 36.09s\r\n```\r\n\r\n```\r\n$ ./node_modules/.bin/tsc --diagnostics --skipLibCheck --noEmit\r\nFiles: 1767\r\nLines: 226078\r\nNodes: 1036945\r\nIdentifiers: 315470\r\nSymbols: 380158\r\nTypes: 137886\r\nMemory used: 500125K\r\nI/O read: 0.83s\r\nI/O write: 0.00s\r\nParse time: 15.20s\r\nBind time: 3.13s\r\nCheck time: 17.59s\r\nEmit time: 0.00s\r\nTotal time: 35.92s\r\n```\r\n\r\n_(I have no idea why `--noEmit` does not reduce \"Total time\" by \"Emit time\" - it is strange)_\r\n\r\nI hope, if we'll have such API or even cache by `tsc`, it can reduce compilation time, especially `Parse time`.\r\n\r\nAlso, in this case, the TypeScript package can be published with already parsed lib files, what can reduce compilation time even without enabling `--skipLibCheck` option.\r\n\r\n## Examples\r\n\r\nFor example, we can override `getSourceFile` method in `CompilerHost` and provide files from cache if file is not changed since last compilation. It can be done via provided methods like `ts.serializeNode(node: ts.Node): string | ByteArray` / `ts.deserializeNode(nodeData: string | ByteArray): ts.Node`.\r\n\r\nAlso it can be added to `tsc` command as arg `--use-cache` (or something like that) to do it by default (but I believe in this case we also need to have new option like `cacheDir` or `--force`).\r\n\r\nThe similar cache can be found in bazel [rules_typescript](https://github.com/bazelbuild/rules_typescript/blob/d4873377218c49d382275546d11fe590f2fa2ef0/internal/tsc_wrapped/compiler_host.ts#L405-L409), but it is in-memory cache.\r\nIn our internal tool we have very similar in-memory cache too (it allows [speedup multiple compilations the same files](https://github.com/TypeStrong/ts-loader/issues/825#issue-354725524)).\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [x] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n","author":{"url":"https://github.com/timocov","@type":"Person","name":"timocov"},"datePublished":"2018-09-04T13:23:57Z","url":"https://github.com/microsoft/TypeScript/issues/26871"}
| 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:1290f867-0e1c-be97-600b-0272cfcf164a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3B4:4BB79:2EAC697:3BABB57:6B01CAAC |
| html-safe-nonce | 21ce057843a19c34f80071c1251547cec3f095a2b1f9c2dee2c26ac4e6ed2a87 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0I0OjRCQjc5OjJFQUM2OTc6M0JBQkI1Nzo2QjAxQ0FBQyIsInZpc2l0b3JfaWQiOiI0Mzg5MjY4MDY3ODk3NjkwNzk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d35fa3ec7a46182a0790be2a016fd23bbb702ae7d04b3d5ca84c6b22141692c3 |
| hovercard-subject-tag | issue:356808394 |
| 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/26871/issue_layout |
| twitter:image | https://opengraph.githubassets.com/571c6dcd87d8cac2533b537a884827b160f898379053279ef6a2e036cbced226/microsoft/TypeScript/issues/26871 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/571c6dcd87d8cac2533b537a884827b160f898379053279ef6a2e036cbced226/microsoft/TypeScript/issues/26871 |
| og:image:alt | Search Terms Serialization, deserialization, dumping, dump source file, compiler cache Related issues #25658, TypeStrong/ts-loader#825 Suggestion I'd like to suggest to add an API to be able to (de... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timocov |
| 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