Skip to content
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

Could threaded transpile-only be faster? #928

Open
cspotcode opened this issue Dec 22, 2019 · 1 comment
Open

Could threaded transpile-only be faster? #928

cspotcode opened this issue Dec 22, 2019 · 1 comment

Comments

@cspotcode
Copy link
Collaborator

I was thinking about worker_threads in node 11 and wondering if moving the ts-node compiler to a pool of worker threads would ever be faster in transpile-only mode. I'm not sure it's worth it, but I want to share my thoughts anyway.

It'll need --files set to eagerly load files instead of waiting for a require() call. If the app loads its entire codebase at startup, then compilation ordering doesn't matter because you need to wait for every file. But if you're only loading a small subset of the codebase, ts-node's thread worker will somehow need to be smart about compiling the right files first. It could analyze the files it loads for import statements or require() calls and prioritize those files for compilation next. I'm not sure how much of a performance boost you'd get, though.

There's also the issue of moving the entirety if ts-node into the worker thread. Otherwise you have to load typescript into the main thread, which seems costly. But maybe not, since we have to wait for the worker to load it anyway?

Hopefully some day I'll have a chance to prototype this and see if it's any faster.

@cspotcode
Copy link
Collaborator Author

This gets more compelling with ESM modules (#1010) since they can be loaded async. As soon as we've parsed tsconfig, we can figure out if worker thread(s) are needed, then launch it/them. Config can be passed as a JSON object. For all transpileModule requests, we can check if a worker is ready, and if so, pass the request to the worker thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants