-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Use v8.serialize when available. #5565
Conversation
very cool |
Codecov Report
@@ Coverage Diff @@
## master #5565 +/- ##
==========================================
+ Coverage 61.67% 61.75% +0.08%
==========================================
Files 213 213
Lines 7160 7165 +5
Branches 4 4
==========================================
+ Hits 4416 4425 +9
+ Misses 2743 2739 -4
Partials 1 1
Continue to review full report at Codecov.
|
packages/jest-haste-map/src/index.js
Outdated
if (version !== process.versions.v8) { | ||
throw new Error('jest-haste-map: v8 versions do not match.'); | ||
} | ||
return hasteMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting null prototype is not necessary with v8.deserialize
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that doesn't meet my expectation:
v8.deserialize(v8.serialize(Object.create(null))).__proto__ === Object.create(null).__proto__ // false
fix incoming
Anyway, would be nice to extract this to a helper/module one day :) |
fs.readFileSync(this._cachePath), | ||
); | ||
if (version !== process.versions.v8) { | ||
throw new Error('jest-haste-map: v8 versions do not match.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be smarter here, like purging the cache and keep it going, but for the moment it's OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does already do that. Exceptions from this function are caught in the parent and a new map is created which will overwrite this one. For all intents and purposes, this error message is not user visible at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@thymikee Yes, we've got to work on that soon; there are other parts where we could hugely benefit from this, like Exciting times ahead! |
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. |
Summary
v8 (in Node 8+) has a new function called
v8.serialize
which can be used to encode/decode JavaScript data structures faster than JSON. This diff changesjest-haste-map
to use the new function in newer versions of Node and falls back to JSON if the serializer/deserializer aren't available. It also does a v8 version check to ensure we aren't trying to read a possible outdated binary blob. Making the cache work across node versions is a non goal and will be broken by this feature. If a user upgrades node, the function will throw and recreate the haste map.I benchmarked this on a 73mb haste map and got the following results averaged over 10 runs:
Reading is ~200ms faster and writing is 500ms faster. I suspect this is because of less validation work and less GC (edit: it's not GC). Since during startup we read the haste map once, write updates and then read it once per worker, this means that on a gigantic repo, this saves 500+200+(200*workers) time, or close to a second of actual time. On most repos out there in the world, there is likely no visible performance difference.
Next steps (up for grabs):
jest-serialize
package that uses either v8 serialize or JSON.jest-serialize
across Jest (jest-worker
,jest-haste-map
) and Metro.Test plan
I updated some of the tests to pass on either node 8+ or node versions below that.