-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Do not check in the transpileModule
API
#50699
Comments
Me. I'm interested in that research! |
I think I want to have the whole story before going there so I'd like to try the proposed optimizations here and compare them. Also to be clear, it was within our very specific setup. When using swc/esbuild "as intended" the results are different! |
It was my understanding that |
Well |
Paging @DanielRosenwasser for thoughts |
I believe this is because the checker is doing this for grammar checks - but the cost comes from the walk, plus the fact that some checking necessarily happens from the checker's walk. The upside of this is that we have parent pointers (which makes things easy for us), and it reduces time-to-interactive in editor situations (since it's not part of the up-front always-on cost of parsing/binding). The downside is that it's still a separate tree walk and there's some incidental type-checking, and that adds up. I think @sandersn's work on #45349 is also relevant - we've spoken about whether or not grammar checks could be folded into a lighter grammar walk that the full checker can periodically jump into - or possibly brought back into the parser/binder. |
My guess is that if someone spent a day or two trying to optimize and eliminate work from |
I think it's a good idea since type checking for complicated types can be costly, but there are some TypeScript features that require type information to emit JavaScript code, like For example the following TypeScript code const enum NotAnObject {
Foo = 1,
}
console.log(NotAnObject.Foo); will be transpiled into JavaScript code: "use strict";
console.log(1 /* NotAnObject.Foo */); TypeScript needs to know In other words, does this API implicitly require |
Yes, |
I think this is now fixed by #58364. Thanks @weswigham! |
Suggestion
🔍 Search Terms
transpileModule
skip typechecking
no typechecking
Semi-related issues found:
--transpileOnly
intsc
, re-open of #4176) #29651✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Modify the
transpileModule
API to mostly do the following:The API itself would be unchanged but would be guaranteed to not hit the type-checker if a certain set of compatible compiler options is set. (deoptimizing options TBD)
Achieving this without modifying TypeScript is currently not possible with the current TypeScript API: there is currently no way to just apply the transforms without running the checker as a
Program
has to be created in the process.Alternatively, if changing
transpileModule
is not possible we would be interested in exposing more minimal API primitives so we could build up this API ourselves:Printer
API that can issue sourcemapsProgram
(and run the checker...)📃 Motivating Example
In our build system, for certain workflows, we introduced a new build mode that runs
transpileModule
instead of compiling and type-checking the full project.transpileModule
is run on a per-file basis as we are reading files into our build stream, meaning there are no inter-file ordering dependencies.Approximative `transpileModule` API usage
With this new mode, we managed to get 4x faster than an equivalent fully-typechecked build! This is an amazing speedup that is appreciated for running common workflows (while VSCode continues to type-check things in the editor).
We are still trying to get faster: most of the time is now spent type-checking inside
transpileModule
, as seen in the CPU flamecharts.We researched using alternative build tools such as swc or esbuild but using their transpile API alone in our setup is not significantly better than using
transpileModule
! (I could do a writeup on this if anyone is interested in that research) However, those other tools do tend to get really fast when they are run standalone and handle file I/O but unfortunately this does not fit our use case.At this point, a pure js-based transform might be the better option and simply using the TypeScript compiler infrastructure would make sense since all the tools to create a relatively fast module type-stripping system should be there but are not exposed through the current API.
💻 Use Cases
Our goal is to be able to keep
transpileModule
and have it go faster if the options don't require checking:By avoiding type-checking code paths when possible (deoptimizing options TBD), we could speed things up significantly again for the users of
transpileModule
.In the future, it could also be the base to then introduce a
tsc
flag for fast unchecked builds as suggested in #29651.This would permittsc
to be significantly faster if opted into with the flag.Deoptimizing options
This is a temporary list that we intend to build up over time:
emitDecoratorMetadata
If you can provide some guidance on whether this would be a good thing to change/fix, along with any implementation constraints/tips, I would be happy to attempt an implementation.
The text was updated successfully, but these errors were encountered: