-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Use the compilation cache when running typescript files through --experimental-transform-types
#54741
Comments
this is interesting, we definitely should cache. I think we already have a cache in place for js files but I'm not 100% |
I think the idea is great though the implementation definitely needs more polishing:
|
Wow, the proposed solution is pretty cool |
I started playing with it, and I realized it probably doesnt make sense. Users should transpile to js with a compilation step and then cache. There is no point in persisting a transpiled ts on disk since its what tsc does. You can already cache the js compiled module. |
The main impact of having a compilation cache is the running speed. The cache can save processor resources and exchange space for time. After all, there is no obvious disadvantage in adding a cache. TypeScript is an interpreted language like JavaScript, not a compiled language. Compiling all .ts files in advance and then running is not very user-friendly. It always feels like two steps in spirit. Compilation and type checking should be a separate optional process rather than a must-have. In a node.js project, I hope to write {
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true,
"allowImportingTsExtensions": true
}
} Because Now many other javascript runtimes, such as deno, bun, support running .ts files directly instead of compiling first, and the performance is very good. I don't know if they cache. |
With TypeScript 5.7 there is a emit flag compatible with strip-types https://devblogs.microsoft.com/typescript/announcing-typescript-5-7-beta/ so you can now transpile. |
Added to #52696 - as mentioned in #54741 (comment) this should tie into the existing compilation cache storage, so that it works with the Can look into it in the coming weeks, as I was also finishing the multi-threaded writes of the cache. I believe technically we could also make ESM-TypeScript transpilation multi-threaded, too, though that would likely require using swc natively instead of using wasm or otherwise the overhead of coordination in multi-threaded JS may cancel out the benefit... |
Started with a prototype here. Technically, this just needs one additional layer of TS -> JS cache, the existing JS -> bytecode cache is applied automatically afterwards. Numbers already look promising (I took
If swc just supports UTF8 -> UTF8 buffers, we can save 2-3.
Used the main branch for comparison to rule out the time saved for JS compilation, although after type stripping there isn't much left in a |
What is the problem this feature will solve?
The flags --experimental-strip-types and --experimental-transform-types enable Node.js to run almost all TypeScript files. #54283
This feature of running .ts files directly is great. I recently removed the step of compiling .ts files to .js and started the project directly through
node entry.ts
, and then directly imported other .ts modules.However, in a large project with many files, compiling .ts files takes up a lot of startup time (about 200ms for all files using .js, and about 700ms for .ts). If there is a compilation cache, skipping the compilation of the same .ts file and directly using the .js compilation result, it will be very efficient.
What is the feature you are proposing to solve the problem?
After I got this idea, I tried to simply modify
lib/internal/modules/esm/translators.js
and add local file cache. Now the speed of running .ts file for the second time is exactly the same as .js.I hope someone can combine .ts compilation cache with the current .js compilation cache in node.js.
@nodejs/typescript
@marco-ippolito @joyeecheung
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: