Improve jest-worker (up to 4x)#5793
Merged
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5793 +/- ##
==========================================
- Coverage 63.74% 63.73% -0.01%
==========================================
Files 216 216
Lines 7929 7938 +9
Branches 4 3 -1
==========================================
+ Hits 5054 5059 +5
- Misses 2874 2878 +4
Partials 1 1
Continue to review full report at Codecov.
|
cpojer
reviewed
Mar 14, 2018
| _options: WorkerOptions; | ||
| _queue: Array<QueueChildMessage>; | ||
| _queue: ?QueueChildMessage; | ||
| _last: ?QueueChildMessage; |
Member
There was a problem hiding this comment.
this is not in the right alphabetical location :P
Member
|
This is really fantastic. Thanks @mjesun, great work! |
Member
|
Beauty!! |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR modifies the way internal worker queues are managed, passing from an array to a linked-list, improving a 10% the current benchmark, and 400% over a new benchmark.
How come this wasn't noticed before?
When
jest-workerwas initially benchmarked, it was done by using not so many jobs (~10k), but very heavy in time. While this is the usual approach (few jobs, lots of time per job), sometimes you have the opposite (i.e. lots of jobs, but each of them very fast). This is actually whatjest-haste-mapdoes.Since the internal queue was an array, re-indexing the queue is a
O(n)operation, which becomes especially relevant on the second scenario. Switching to a linked list means that all operations for advancing the queue becomeO(1), no matter its length. This results in massive speed improvements on really long queues.Some benchmarks
Using the extended performance test, the
emptyfunction, called 100,000 times results in:Now, with the change, it results in:
What about the existing metrics?
The previous metric (which we initially used for benchmarking,
loadTestcalled 10,000 times), has also improved, but only slightly, since that one was already optimized:Tests
I ensured all tests pass, but I also added some slight modifications into the
__performance__tests__so that you can pass an arbitrary worker method as well as an arbitrary number of iterations. This allowed me to test the other scenario.On a personal note: this is actually WHY algorithms and data structures knowledge IS important for a frontend developer! 🙂