-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
[Bugfix] Ensure stability of filename cache-keys #909
Conversation
Thanks! Is it possible that the CI failure is related to this change? |
@nicolo-ribaudo failure is occurring locally too, I will investigate & address (most likely later tonight, or tomorrow). |
@nicolo-ribaudo quick-update I'll do some additional debugging this afternoon, but my initial debugging pass suggests this test failure may actually be an example of an erroneous cache miss now corrected with this change. I'm not yet 100% convinced, but intend to continue investigation this afternoon. |
6fb3ede
to
593dca6
Compare
test/cache.test.js
Outdated
@@ -376,7 +376,7 @@ test.cb("should allow to specify the .babelrc file", t => { | |||
|
|||
fs.readdir(t.context.cacheDirectory, (err, files) => { | |||
t.is(err, null); | |||
t.true(files.length === 2); | |||
t.true(files.length === 1); |
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.
This changes because the cached files now have an identical key.
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.
Well, it's good that we can actually see the improvement caused by this change 😄
@nicolo-ribaudo I believe in-fact the test failures where an example of an unstable cache key. |
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.
Thanks!
@hzoo / @nicolo-ribaudo what are the next steps? Anything I can help with? |
I clone the repo and here the benchmark result. It seems that
|
@JLHwung I can switch to that 1, give me a sec. |
|
593dca6
to
fde5dfd
Compare
There haven't been new commits, but there are no reported bugs. It could be "maintianed, but working". We should only self-host it if we find a bug that we need to fix, and the maintainer doesn't accept PRs. |
I agree with @nicolo-ribaudo's POV. |
Designing general stable
Combining these two tricks I see 150% improvement (named as
The serializer could be faster than the native I have pushed the branch in https://github.com/JLHwung/fast-stable-stringify/tree/babel |
@JLHwung additional performance here sounds great. |
@JLHwung et.al what are the next steps? |
My personal opinion here: Since we don't have to use JSON stringify, I think we can host our own property stable config serializer. Now that the cache key is updated and the old cache should probably be invalidated, I think we should inform users on the next release note that we recommend running |
@JLHwung let me know when your variant of stringification is published, and I can include it here... |
@stefanpenner We don't have to publish a new package, since it is not JSON and meant to be used in |
I'm down with in-lining our changes as in JLHwung/fast-stable-stringify@f5b0ca9 in the repo |
ok |
Sorry for the super late reply. I have rebased this PR and switched to our in-house config serializer. Because this PR will change the cache identification, babel-loader can not reused cache generated by previous versions, therefore I marked this PR as a breaking change. |
`JSON.stringify(structure)` isn’t inherently stable as it relies on various internal details of how `structure` was created. As written, if a given babel configuration is create in an dynamic manner, it is possible for babel-loader to have spurious cache misses. To address this, we can use one of the many stable stringify alternatives. For this PR I have selected [fast-stable-stringify](https://www.npmjs.com/package/fast-stable-stringify) for that task, as it appears both popular and it’s benchmarks look promising. This PR does not explicitly include tests, as testing this is both tricky to test in this context, and the important tests are contained within fast-stable-stringify itself.
The options will be serialized in the cache#filename function with the cache identifier, so we don't have to include options in the cache identifier.
Nice, great to see this land! |
[Bugfix] Ensure stability of filename cache-keys
JSON.stringify(structure)
isn’t inherently stable as it relies on variousinternal details of how
structure
was created.As written, if a given babel configuration is create in an dynamic manner,
it is possible for babel-loader to have spurious cache misses.
To address this, we can use one of the many stable stringify alternatives.
For this PR I have selected fast-json-stable-stringify
for that task, as it appears both popular and it’s benchmarks look promising.
This PR does not explicitly include tests, as testing this is both tricky
to test in this context, and the important tests are contained within
fast-json-stable-stringify itself.
Please Read the CONTRIBUTING Guidelines
In particular the portion on Commit Message Formatting
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
cache keys are unstable, causing occasional cache misses
What is the new behavior?
cache keys should be stable
Does this PR introduce a breaking change?