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.
Running all tests was getting a bit slow on my laptop (about 32s slow for
test:languages
), so I wanted to make them a bit faster.On my PC, I started with 14s for just
npm run test:languages
. The time itself was measured by mocha, so times aren't terribly accurate but +-0.5s don't really matter here.Because all file reads are perfectly cached already, I tried to make the checks (#1803) faster. To do that I made a module that contains both functions and is required like any other node module. No more VMs.
That alone brought the time down to 8s.
That worked so well, so I did something similar for language loading. Instead of using a VM, I make a JS function out of every file and pass that function a Prism object. Down to 5s.
The last thing I changed was the
createEmptyPrism
function which still uses a VM, so I changed that and was down to 1s.From 14s to 1s.
Because what I make faster was the functions that literally every test needs, all tests became faster, not just the language tests. The whole test suite now takes about 10s total on my PC.
The problem with this approach is that there is very little isolation between Prism's files. To tried to use Node's VMs a bit more efficiently by using
vm.Script
object, so the source files don't have to be parsed com compiled every time but that saved just 1s (So from 14s -> 13s).