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

Fix non-deterministic builds between project directories #8869

Merged
merged 13 commits into from
Mar 15, 2023

Conversation

mattcompiles
Copy link
Contributor

↪️ Pull Request

We noticed we were getting different build outputs when running builds of the same commit in different directories. This PR resolves the two issues we were running into.

Firstly, the JS transformer adds hashed import specifiers to require calls but the hash is partly seeded from the absolute filepath. This may get cleaned up afterwards, but it's possible the differing hashes can cause the files to have slightly different output sizes which has downstream effects in the bundling phase. I also think file building should be deterministic in general anyway as it will make cross system caching feasible in the long term.

Secondly, when shared bundles are deleted and merged into the entry, the assets of the entry bundle are now likely out of order. This was fixed by sorting the assets of the modified bundles. This issue may have simply exacerbated the first one from a project root perspective.

🚨 Test instructions

Existing tests should be sufficient for the transformer change. Not sure how to test the shared bundle issue?

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@parcel-benchmark
Copy link

parcel-benchmark commented Mar 6, 2023

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 2.05s +5.00ms
Cached 468.00ms +52.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

React HackerNews ✅

Timings

Description Time Difference
Cold 9.06s +483.00ms ⚠️
Cached 569.00ms -30.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/index.js 463.02kb +0.00b 1.39s +87.00ms ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/logo.c5bb83f1.png 246.00b +0.00b 453.00ms +23.00ms ⚠️

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.31m -1.56s
Cached 2.81s -39.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/pdfRenderer.4f3765de.js 1.11mb +0.00b 16.37s -1.14s 🚀
dist/refractor.c460668c.js 601.81kb +0.00b 11.60s -3.86s 🚀
dist/component-lazy.60375b05.js 60.45kb +0.00b 7.45s -1.29s 🚀
dist/DatePicker.3a60f244.js 48.38kb +0.00b 8.21s -523.00ms 🚀
dist/DatePicker.b0a4d8f4.js 25.21kb +0.00b 8.21s -523.00ms 🚀
dist/ru.896915b9.js 2.94kb +0.00b 8.23s -511.00ms 🚀
dist/ResourcedEmojiComponent.04d67e5e.js 2.69kb +0.00b 8.21s -523.00ms 🚀
dist/pl.5f36d63e.js 2.38kb +0.00b 8.22s -513.00ms 🚀
dist/cs.971d1d60.js 2.36kb +0.00b 8.21s -523.00ms 🚀
dist/de.6efbb375.js 2.30kb +0.00b 8.21s -523.00ms 🚀
dist/fr.af2c92ae.js 2.25kb +0.00b 8.22s -514.00ms 🚀
dist/es.23f0c164.js 2.25kb +0.00b 8.21s -523.00ms 🚀
dist/hu.8323f36b.js 2.23kb +0.00b 8.22s -514.00ms 🚀
dist/fi.7ed4b1b5.js 2.22kb +0.00b 8.22s -514.00ms 🚀
dist/ja.5653161c.js 2.22kb +0.00b 8.22s -514.00ms 🚀
dist/pt_BR.eccfad73.js 2.19kb +0.00b 8.23s -511.00ms 🚀
dist/ko.2cf2bbda.js 2.11kb +0.00b 8.22s -513.00ms 🚀
dist/it.601d375a.js 2.10kb +0.00b 8.22s -514.00ms 🚀
dist/nb.b300dd3e.js 2.09kb +0.00b 8.22s -513.00ms 🚀
dist/da.21385cf2.js 2.07kb +0.00b 8.21s -522.00ms 🚀
dist/nl.3999ea58.js 2.07kb +0.00b 8.22s -513.00ms 🚀
dist/feedback.fd1f6260.js 1.89kb +0.00b 8.21s -523.00ms 🚀
dist/heading6.974f167d.js 1.49kb +0.00b 8.21s -522.00ms 🚀
dist/expand.801fc3a0.js 1.31kb +0.00b 8.21s -522.00ms 🚀
dist/sk.101f1705.js 786.00b +0.00b 8.23s -3.18s 🚀
dist/pt_PT.402f9c4e.js 765.00b +0.00b 8.22s -513.00ms 🚀
dist/et.69382942.js 763.00b +0.00b 8.21s -523.00ms 🚀
dist/is.5b945719.js 625.00b +0.00b 8.22s -514.00ms 🚀
dist/ro.a6eff34a.js 612.00b +0.00b 8.22s -514.00ms 🚀
dist/en_GB.61f7112a.js 602.00b +0.00b 8.21s -522.00ms 🚀
dist/en.41261459.js 599.00b +0.00b 8.21s -523.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/refractor.c460668c.js 601.81kb +0.00b 14.96s -770.00ms 🚀
dist/media-viewer.bd165005.js 542.15kb +0.00b 10.69s -5.06s 🚀
dist/popup.2cbde099.js 329.78kb +0.00b 14.96s -773.00ms 🚀
dist/EmojiPickerComponent.a25bd8e7.js 196.67kb +0.00b 10.69s -5.05s 🚀
dist/esm.6df2a542.js 64.51kb +0.00b 14.96s -772.00ms 🚀
dist/archive.503fa405.js 61.48kb +0.00b 14.96s -770.00ms 🚀
dist/esm.bd488cd8.js 40.24kb +0.00b 14.96s -782.00ms 🚀
dist/smartMediaEditor.8713e5a6.js 22.24kb +0.00b 14.96s -781.00ms 🚀
dist/esm.a10f92b5.js 21.06kb +0.00b 14.96s -781.00ms 🚀
dist/dropzone.4b8113c9.js 14.00kb +0.00b 14.96s -781.00ms 🚀
dist/dropzone.ae8c8d79.js 11.95kb +0.00b 14.96s -781.00ms 🚀
dist/Toolbar.7fda8a1b.js 9.30kb +0.00b 14.96s -781.00ms 🚀
dist/clipboard.ef3ddc39.js 8.22kb +0.00b 14.96s -781.00ms 🚀
dist/mobile-upload.31f0e326.js 8.08kb +0.00b 14.96s -780.00ms 🚀
dist/browser.0a7fd453.js 7.48kb +0.00b 14.96s -772.00ms 🚀
dist/index.6d0e3617.js 7.32kb +0.00b 14.96s -781.00ms 🚀
dist/media-viewer-analytics-error-boundary.e6109a6a.js 3.46kb +0.00b 14.96s -781.00ms 🚀
dist/media-picker-analytics-error-boundary.627962a5.js 3.46kb +0.00b 14.96s -781.00ms 🚀
dist/media-card-analytics-error-boundary.ec5ff8ee.js 3.45kb +0.00b 14.96s -770.00ms 🚀
dist/workerHasher.13de9709.js 1.72kb +0.00b 14.96s -772.00ms 🚀
dist/workerHasher.99c37306.js 1.72kb +0.00b 14.96s -781.00ms 🚀
dist/workerHasher.c5ba46bc.js 1.72kb +0.00b 14.96s -781.00ms 🚀
dist/simpleHasher.a19114f9.js 687.00b +0.00b 14.96s -781.00ms 🚀
dist/simpleHasher.023b58fa.js 687.00b +0.00b 14.96s -781.00ms 🚀
dist/simpleHasher.97222d8a.js 687.00b +0.00b 14.96s -781.00ms 🚀

Three.js ✅

Timings

Description Time Difference
Cold 6.24s -20.00ms
Cached 372.00ms +7.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/Three.js 572.22kb +0.00b 1.35s -110.00ms 🚀

Click here to view a detailed benchmark overview.

}),
);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if you could use BitSet for bundle.assets here? Then when you do bundle.assets.add it would just be setting a bit corresponding to the position within assets. When we take the ideal graph and convert it back to the legacy graph we could iterate in asset order (as BitSet#values() does).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Funny you mention this because I considered that approach as well but was worried this iteration cost might not be worth it. You've inspired me to try it though. Will report back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devongovett Just realised it'd be hard to use the BitSet here as we need to create bundles before we know the full list of assets as we add them during the traverse.

Copy link
Member

Choose a reason for hiding this comment

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

You could create the bitset earlier maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could, but I'd have to add a second full asset traverse to collect the list of all assets before starting the main traverse. Unless there's some other cheap way to get the list of all assets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After migrating all asset sets to BitSets I actually saw a drop in perf. This is due to the values() extraction being too expensive. I think there's potential to use BitSet more widely in the bundler but it would require a larger rethink to optimise around its benefits.

tl;dr let's just sort for now.

@AGawrys AGawrys self-requested a review March 14, 2023 23:56
@mattcompiles mattcompiles merged commit 41ed29f into v2 Mar 15, 2023
@mattcompiles mattcompiles deleted the mjones/shared-asset-order branch March 15, 2023 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants