-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
TS compiler loads modules synchronously #2626
Comments
I don't think you are going to get the TypeScript compiler to work asynchronously. It is sync throughout, which has to do a lot with the way the underlying hosts have to behave and the way the analysis has to happen. There are no async APIs. Ref: microsoft/TypeScript#29361 The only possible path is point two, but I would say that you would send 1 message to kick off the loading. TypeScript just needs to know what the resolved module name is, so when it goes to How is it really a blocker for the rewrite, other than behaving differently than you would like it? |
Thanks for pointing this out, after quick scan of TS compiler API I felt that it might not be possible to make it async.
That's correct. I'm okay with compilation being synchronous but if downloading of modules can be parallelized we should definitely explore this possibility - and since
It's not a blocker for rewrite - just this issue was uncovered during rewrite, but in conversation with @ry we agreed that downloading of modules should be somehow optimized before 1.0. |
It's unfortunate that typescript doesn't support async module loading. I wonder if Otherwise using resolveModuleNames to queue up async download would still be helpful. If A imports B, C, D. We currently download B, C, and D serially. We could return the module name synchronously, but start the download in the background. Later we would actually wait on the B download, but at least C and D would still be downloading. I think this is important to consider during the refactor of DenoDir. |
Yeah, that is part of the Automatic Type Acquisition system, where TypeScript will go off and request of VSCode to install a type definition ( |
This issue came up when working on rewrite of DenoDir and is a blocker for v1.0 (#2473)
In the current setup TS compiler requests module synchronously one-by-one.
Modules are requested in two separate (synchronous) functions:
resolveModuleNames
- which is called for all imports in given TS file, compiler wants to know fully resolved URL to that module, but we're actually downloading the module in this step by issuingop_fetch_module_meta_data
(synchronous).getSourceFile
- this function returns source code of module. Sinceop_fetch_module_meta_data
was already called inresolveModuleNames
the files are already downloaded.Ideas for solutions:
resolveModuleNames
I wanted to send multiple specifiers to Rust to kick off parallel download of modules and block on it, but @ry suggested it's not possible since it's sync op.resolveModuleNames
send one message to Rust for each specifier kicking off download of that module in background - this could be represented asModuleMetaDataFuture
that is stored inDenoDir
. During subsequentgetSourceFile
call that future should be resolved. Although I'm not sure if it doesn't present the same problem as above - future won't be polled because it's a sync op.resolveModuleNames
andgetSourceFile
CC @ry @kitsonk
The text was updated successfully, but these errors were encountered: