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

Faster tests #2165

Merged
merged 2 commits into from Jun 27, 2020
Merged

Faster tests #2165

merged 2 commits into from Jun 27, 2020

Conversation

RunDevelopment
Copy link
Member

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).

Copy link
Member

@mAAdhaTTah mAAdhaTTah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm into this. If we're still creating a new Prism instance in each test, the overhead of a whole VM isn't necessary to prevent leakages.

@RunDevelopment RunDevelopment merged commit e756be3 into PrismJS:master Jun 27, 2020
@RunDevelopment RunDevelopment deleted the faster-tests branch June 27, 2020 19:43
quentinvernot pushed a commit to TankerHQ/prismjs that referenced this pull request Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants