-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
This pull request has been linked to and will mark 1 task as "Done" when merged:
|
Benchmark ResultsKitchen Sink ✅
Timings
Cold Bundles
Cached Bundles
React HackerNews ✅
Timings
Cold Bundles
Cached BundlesNo bundle changes detected. AtlasKit Editor ✅
Timings
Cold Bundles
Cached Bundles
Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached Bundles
|
Apparently it's a known bug. @evanw crafted a novel workaround for this: evanw/esbuild@9ea2076 |
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>, |
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.
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
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.
@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'; |
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.
init
only exists in the wasm version?
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.
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).
// 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, | ||
}; |
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 can remove this again once RReverser/serde-wasm-bindgen#12 is merged)
result.hoist_result != null | ||
? { | ||
...result.hoist_result, | ||
imported_symbols: Object.fromEntries([ |
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.
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.
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.
You're right. But even better, I can remove this altogether now: #6413
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:
Option<>
is serialized intoundefined
instead ofnull