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

Wasm version of JS Transformer #6360

Merged
merged 13 commits into from Jun 3, 2021
Merged

Wasm version of JS Transformer #6360

merged 13 commits into from Jun 3, 2021

Conversation

mischnic
Copy link
Member

@mischnic mischnic commented May 26, 2021

The Wasm version works, but for some reason Node waits for 2 seconds after the build is finished before actually exiting. (The napi version is unchanged!)

Wasm size: 5.3mb

The Wasm version not used on any platform (yet).

Closes T-951

There are 16 failing integration tests when switching to wasm:

  • fs inlining doesn't work
  • sometimes an Option<> is serialized into undefined instead of null

@mischnic mischnic requested a review from devongovett May 26, 2021 18:40
@height
Copy link

height bot commented May 26, 2021

This pull request has been linked to and will mark 1 task as "Done" when merged:

💡Tip: You can link multiple Height tasks to a pull request.

@parcel-benchmark
Copy link

parcel-benchmark commented May 26, 2021

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.92s -88.00ms
Cached 421.00ms -17.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/index.d36d7912.css 77.00b +0.00b 935.00ms -53.00ms 🚀
dist/modern/index.cc45e040.css 77.00b +0.00b 934.00ms -54.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.d5807e82.webp 102.94kb +0.00b 51.00ms -10.00ms 🚀
dist/modern/parcel.d5807e82.webp 102.94kb +0.00b 76.00ms +14.00ms ⚠️
dist/legacy/index.6e5b41a7.js 2.00kb +0.00b 89.00ms -8.00ms 🚀
dist/modern/index.ed84bbeb.js 2.00kb +0.00b 88.00ms -9.00ms 🚀
dist/legacy/index.html 701.00b +0.00b 85.00ms -13.00ms 🚀
dist/modern/index.html 701.00b +0.00b 83.00ms -14.00ms 🚀
dist/legacy/index.d36d7912.css 77.00b +0.00b 82.00ms -14.00ms 🚀
dist/modern/index.cc45e040.css 77.00b +0.00b 84.00ms -13.00ms 🚀

React HackerNews ✅

Timings

Description Time Difference
Cold 11.30s -307.00ms
Cached 682.00ms -9.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/logo.24c8bf9e.png 274.00b +0.00b 25.00ms -5.28s 🚀

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.31m +91.00ms
Cached 3.10s -15.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/index.22b0a002.js 2.60mb +32.00b ⚠️ 30.46s +54.00ms
dist/pdfRenderer.4dcd091a.js 411.56kb +0.00b 50.56s -9.38s 🚀
dist/popup.83b13bc7.js 209.85kb +0.00b 50.56s -9.38s 🚀
dist/media-viewer.3ef9eadb.js 74.99kb +0.00b 50.56s -9.38s 🚀
dist/card.914b60a9.js 62.67kb +0.00b 50.56s -9.38s 🚀
dist/esm.5a4b08a2.js 33.24kb +0.00b 50.56s -9.38s 🚀
dist/ui.2a24dcba.js 14.94kb +0.00b 50.56s -9.38s 🚀
dist/dropzone.725ce10e.js 12.15kb +0.00b 50.56s -9.38s 🚀
dist/card.006509f3.js 5.96kb +0.00b 50.56s -9.38s 🚀
dist/EmojiPickerComponent.e8d86cb3.js 3.72kb +0.00b 50.56s -9.38s 🚀
dist/dropzone.2340e1e4.js 3.29kb +0.00b 50.56s -9.38s 🚀
dist/ResourcedEmojiComponent.425492a2.js 2.12kb +0.00b 50.56s -9.38s 🚀
dist/feedback.a4084b43.js 1.77kb +0.00b 49.94s +18.14s ⚠️
dist/workerHasher.a91c28d5.js 1.63kb +0.00b 50.56s -9.38s 🚀
dist/heading6.2df789d9.js 1.51kb +0.00b 49.94s +18.14s ⚠️
dist/heading3.99e77e15.js 1.49kb +0.00b 49.94s +18.14s ⚠️
dist/heading5.c9eff376.js 1.38kb +0.00b 49.94s +18.14s ⚠️
dist/expand.c97517e7.js 1.29kb +0.00b 49.94s +18.14s ⚠️
dist/heading4.a48496c5.js 1.27kb +0.00b 49.94s +18.14s ⚠️
dist/media-card-analytics-error-boundary.92f81a75.js 1.12kb +0.00b 50.56s -9.38s 🚀
dist/media-viewer-analytics-error-boundary.c51589b7.js 964.00b +0.00b 50.56s -9.38s 🚀
dist/media-picker-analytics-error-boundary.da55e63c.js 964.00b +0.00b 50.56s -9.38s 🚀
dist/media-card-analytics-error-boundary.0bc87153.js 960.00b +0.00b 50.56s -9.38s 🚀
dist/simpleHasher.74d2cfec.js 641.00b +0.00b 50.56s -9.38s 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.f2546652.js 2.60mb +16.00b ⚠️ 163.00ms -26.00ms 🚀
dist/EmojiPickerComponent.a658fec7.js 147.28kb +0.00b 213.00ms -25.00ms 🚀
dist/card.7de65a30.js 62.67kb +0.00b 214.00ms -26.00ms 🚀
dist/Modal.3de61f7e.js 45.31kb +0.00b 168.00ms -27.00ms 🚀
dist/component.f2069ab7.js 37.59kb +0.00b 166.00ms -27.00ms 🚀
dist/esm.75658928.js 33.24kb +0.00b 213.00ms -26.00ms 🚀
dist/component.319ca86f.js 24.95kb +0.00b 170.00ms -26.00ms 🚀
dist/DatePicker.0a467264.js 22.99kb +0.00b 212.00ms -26.00ms 🚀
dist/js.85def1c2.js 17.33kb +0.00b 169.00ms -27.00ms 🚀
dist/ui.ae7e574e.js 14.94kb +0.00b 213.00ms -26.00ms 🚀
dist/workerHasher.95f27d4e.js 11.81kb +0.00b 213.00ms -26.00ms 🚀
dist/component.9e1648d9.js 6.82kb +0.00b 215.00ms +18.00ms ⚠️
dist/card.006509f3.js 5.96kb +0.00b 214.00ms -28.00ms 🚀
dist/EmojiPickerComponent.e8d86cb3.js 3.72kb +0.00b 213.00ms -26.00ms 🚀
dist/png-chunks-extract.26a58e9e.js 3.58kb +0.00b 170.00ms -25.00ms 🚀
dist/index.90d3dc33.css 3.46kb +0.00b 263.00ms -14.00ms 🚀
dist/Modal.97b7b979.js 3.15kb +0.00b 167.00ms -27.00ms 🚀
dist/16.ca688077.js 2.36kb +0.00b 165.00ms -25.00ms 🚀
dist/ResourcedEmojiComponent.425492a2.js 2.12kb +0.00b 213.00ms -26.00ms 🚀
dist/date.13837189.js 1.86kb +0.00b 173.00ms -27.00ms 🚀
dist/images.a51e31c2.js 1.80kb +0.00b 175.00ms -28.00ms 🚀
dist/feedback.a4084b43.js 1.77kb +0.00b 192.00ms -34.00ms 🚀
dist/16.b8c83009.js 1.75kb +0.00b 227.00ms -45.00ms 🚀
dist/16.f48613ba.js 1.68kb +0.00b 216.00ms -53.00ms 🚀
dist/workerHasher.a91c28d5.js 1.63kb +0.00b 213.00ms -26.00ms 🚀
dist/list-number.494da4e7.js 1.59kb +0.00b 178.00ms -27.00ms 🚀
dist/status.8783408d.js 1.59kb +0.00b 186.00ms -25.00ms 🚀
dist/code.677bd70c.js 1.51kb +0.00b 172.00ms -27.00ms 🚀
dist/heading6.2df789d9.js 1.51kb +0.00b 191.00ms -25.00ms 🚀
dist/heading3.99e77e15.js 1.49kb +0.00b 189.00ms -25.00ms 🚀
dist/link.eecf8ee1.js 1.43kb +0.00b 177.00ms -27.00ms 🚀
dist/16.0f105e82.js 1.40kb +0.00b 215.00ms -55.00ms 🚀
dist/heading5.c9eff376.js 1.38kb +0.00b 191.00ms -25.00ms 🚀
dist/emoji.e0bb5bdd.js 1.36kb +0.00b 175.00ms -27.00ms 🚀
dist/16.2475b7ab.js 1.35kb +0.00b 216.00ms -52.00ms 🚀
dist/16.24ecf6d5.js 1.35kb +0.00b 216.00ms -53.00ms 🚀
dist/16.fe096c73.js 1.33kb +0.00b 260.00ms -14.00ms 🚀
dist/16.9c0dd14e.js 1.33kb +0.00b 166.00ms -26.00ms 🚀
dist/heading2.689c1725.js 1.32kb +0.00b 188.00ms -26.00ms 🚀
dist/16.f6f07bdf.js 1.29kb +0.00b 232.00ms -41.00ms 🚀
dist/expand.c97517e7.js 1.29kb +0.00b 212.00ms -14.00ms 🚀
dist/heading4.a48496c5.js 1.27kb +0.00b 190.00ms -25.00ms 🚀
dist/16.abb96752.js 1.25kb +0.00b 227.00ms -45.00ms 🚀
dist/16.8a916ec3.js 1.22kb +0.00b 165.00ms -25.00ms 🚀
dist/16.5ab0c52f.js 1.21kb +0.00b 232.00ms -40.00ms 🚀
dist/16.17b379b7.js 1.20kb +0.00b 170.00ms -27.00ms 🚀
dist/mention.7513d265.js 1.20kb +0.00b 179.00ms -27.00ms 🚀
dist/layout.a2215d1e.js 1.18kb +0.00b 176.00ms -27.00ms 🚀
dist/Modal.71b21a38.js 1.17kb +0.00b 169.00ms -26.00ms 🚀
dist/16.dc7fba57.js 1.16kb +0.00b 227.00ms -44.00ms 🚀
dist/heading1.53882705.js 1.16kb +0.00b 188.00ms -25.00ms 🚀
dist/16.4947d5d2.js 1.16kb +0.00b 166.00ms -25.00ms 🚀
dist/divider.61f72909.js 1.16kb +0.00b 174.00ms -27.00ms 🚀
dist/quote.ac356b63.js 1.15kb +0.00b 185.00ms -26.00ms 🚀
dist/16.61848cd9.js 1.15kb +0.00b 216.00ms -53.00ms 🚀
dist/16.f88600cd.js 1.15kb +0.00b 216.00ms -54.00ms 🚀
dist/16.3457832f.js 1.15kb +0.00b 227.00ms -44.00ms 🚀
dist/16.59da43e0.js 1.15kb +0.00b 215.00ms -53.00ms 🚀
dist/action.03622130.js 1.13kb +0.00b 171.00ms -27.00ms 🚀
dist/component.0faea072.js 1.12kb +0.00b 163.00ms -26.00ms 🚀
dist/media-card-analytics-error-boundary.92f81a75.js 1.12kb +0.00b 214.00ms -27.00ms 🚀
dist/decision.e8963abf.js 1.12kb +0.00b 173.00ms -27.00ms 🚀
dist/panel-warning.d87689fa.js 1.11kb +0.00b 183.00ms -26.00ms 🚀
dist/16.71584d67.js 1.11kb +0.00b 164.00ms -27.00ms 🚀
dist/list.452d2378.js 1.08kb +0.00b 178.00ms -28.00ms 🚀
dist/16.d79d0001.js 1.07kb +0.00b 232.00ms -41.00ms 🚀
dist/panel-error.2d1266a1.js 1.01kb +0.00b 180.00ms -27.00ms 🚀
dist/panel.2fa2f198.js 1.01kb +0.00b 184.00ms -26.00ms 🚀
dist/table.5143dd29.js 1022.00b +0.00b 187.00ms -25.00ms 🚀
dist/panel-success.8c4cf740.js 978.00b +0.00b 182.00ms -27.00ms 🚀
dist/panel-note.aa22bfaa.js 974.00b +0.00b 181.00ms -27.00ms 🚀
dist/media-card-analytics-error-boundary.b94e1438.js 960.00b +0.00b 214.00ms -26.00ms 🚀
dist/simpleHasher.74d2cfec.js 641.00b +0.00b 213.00ms -26.00ms 🚀
dist/index.html 119.00b +0.00b 112.00ms -25.00ms 🚀

Three.js ✅

Timings

Description Time Difference
Cold 8.03s +182.00ms
Cached 598.00ms -29.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

Bundle Size Difference Time Difference
dist/Three.js 579.69kb +0.00b 81.00ms +11.00ms ⚠️

Click here to view a detailed benchmark overview.

@kzc
Copy link

kzc commented May 28, 2021

but for some reason Node waits for 2 seconds after the build is finished before actually exiting

Apparently it's a known bug.

@evanw crafted a novel workaround for this: evanw/esbuild@9ea2076

@mischnic
Copy link
Member Author

Thanks!

Related: nodejs/node#36616, swc-project/swc#1352

But thankfully, the primary usecase at the moment is the browser anyway. For now, we also don't fallback on wasm if there's no suitable prebuild native module.

#[serde(with = "serde_bytes")]
code: &'a [u8],
code: Vec<u8>,
Copy link
Member Author

@mischnic mischnic May 29, 2021

Choose a reason for hiding this comment

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

Not sure whether this being a Vec has worse performance, and if yes, how to still use a slice

AFAICT, before Vec was a local variable, so it shouldn't really change anything

Copy link
Member Author

Choose a reason for hiding this comment

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

@devongovett What did you see while profiling that motivated the change from string to &'a [u8]?

@@ -3,7 +3,7 @@ import type {JSONObject, EnvMap} from '@parcel/types';
import type {SchemaEntity} from '@parcel/utils';
import SourceMap from '@parcel/source-map';
import {Transformer} from '@parcel/plugin';
import {transform} from './native';
import {init, transform} from '../native';
Copy link
Member

Choose a reason for hiding this comment

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

init only exists in the wasm version?

Copy link
Member Author

@mischnic mischnic Jun 3, 2021

Choose a reason for hiding this comment

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

Yes. It's a promise (not a function returning a promise), so we don't really need that stub export for the non-wasm version, it's simply await undefined then.

It's only needed in the web wasm version (Node wasm is synchronous and native of course as well).

Comment on lines +11 to +34
// https://github.com/cloudflare/serde-wasm-bindgen/issues/10
dependencies: result.dependencies?.map(d => ({
...d,
attributes:
d.attributes != null
? Object.fromEntries([...d.attributes])
: undefined,
})),
hoist_result:
result.hoist_result != null
? {
...result.hoist_result,
imported_symbols: Object.fromEntries([
...result.hoist_result.imported_symbols,
]),
exported_symbols: Object.fromEntries([
...result.hoist_result.exported_symbols,
]),
dynamic_imports: Object.fromEntries([
...result.hoist_result.dynamic_imports,
]),
}
: undefined,
};
Copy link
Member Author

Choose a reason for hiding this comment

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

(We can remove this again once RReverser/serde-wasm-bindgen#12 is merged)

@mischnic mischnic merged commit 11c576f into v2 Jun 3, 2021
@mischnic mischnic deleted the swc-wasm branch June 3, 2021 20:26
result.hoist_result != null
? {
...result.hoist_result,
imported_symbols: Object.fromEntries([

Choose a reason for hiding this comment

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

Just noticed this while looking at the link from other PR and wanted to note here too that you can use Object.fromEntries(result.hoist_result.imported_symbols) directly without converting to an intermediate array.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. But even better, I can remove this altogether now: #6413

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

5 participants