Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
I'm using ts-node within docker with sources and node_modules mounted as volumes. I noticed that it's a bit slower than running it directly on host. That's on linux but on mac it's drastically worse so I investigated the issue a little bit more.
First thing to do was to enable debug mode via
TS_NODE_DEBUG
env variable. It showed multiplefileExists
anddirectoryExists
operations. Those operations are more costly when using in docker mounted volumes. And much more costly when using it on mac. But when I sorted the output I was able to see that many of those operations are repeated several times for the same file/directories, for example:So I started to play with it a little bit. I thought I could cache the results of those functions and I wrote a simple
cached
function to do it. Here are benchmarks for my project (on linux):I run it multiple times.
docker-compose down
is needed to actually remove existing containers in order to get rid of any temporary files. As you can see both total time and time spent in system calls was decreased. When using on mac it can save you literally minutes and don't force you to use solutions likedocker-sync
.