-
-
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
Changes from 11 commits
6705b5d
705c361
6ef1b96
8acdf59
c7b6299
3cb05f6
a3320eb
6e6aef7
2d14dd2
fee33cf
9fe5d8a
bcae9b4
0718a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = ["packages/transformers/js", "packages/utils/fs-search"] | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
# lto = true | ||
members = [ | ||
"packages/transformers/js/core", | ||
"packages/transformers/js/napi", | ||
"packages/transformers/js/wasm", | ||
"packages/utils/fs-search", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
authors = ["Devon Govett <devongovett@gmail.com>"] | ||
name = "parcel-js-swc-napi" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
napi = { version = "1", features = ["serde-json"] } | ||
napi-derive = "1" | ||
parcel-js-swc-core = { path = "../core" } | ||
|
||
[target.'cfg(target_os = "macos")'.dependencies] | ||
jemallocator = { version = "0.3.2", features = ["disable_initial_exec_tls"] } | ||
|
||
[target.'cfg(windows)'.dependencies] | ||
mimalloc = { version = "0.1.25", default-features = false } | ||
|
||
[build-dependencies] | ||
napi-build = { version = "1" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extern crate napi; | ||
#[macro_use] | ||
extern crate napi_derive; | ||
extern crate parcel_js_swc_core; | ||
|
||
use napi::{CallContext, JsObject, JsUnknown, Result}; | ||
|
||
#[cfg(target_os = "macos")] | ||
#[global_allocator] | ||
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
|
||
#[cfg(windows)] | ||
#[global_allocator] | ||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; | ||
|
||
#[js_function(1)] | ||
fn transform(ctx: CallContext) -> Result<JsUnknown> { | ||
let opts = ctx.get::<JsObject>(0)?; | ||
let config: parcel_js_swc_core::Config = ctx.env.from_js_value(opts)?; | ||
|
||
let result = parcel_js_swc_core::transform(config)?; | ||
ctx.env.to_js_value(&result) | ||
} | ||
|
||
#[module_exports] | ||
fn init(mut exports: JsObject) -> Result<()> { | ||
exports.create_named_method("transform", transform)?; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import initFn, {transform} from './wasm/dist-web/parcel_js_swc_wasm.js'; | ||
|
||
export const init = initFn(); | ||
|
||
function transformWrapper(config) { | ||
let result = transform(config); | ||
return { | ||
...result, | ||
// Hydrate Uint8Array into Buffer | ||
code: Buffer.from(result.code.buffer), | ||
// 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([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
...result.hoist_result.imported_symbols, | ||
]), | ||
exported_symbols: Object.fromEntries([ | ||
...result.hoist_result.exported_symbols, | ||
]), | ||
dynamic_imports: Object.fromEntries([ | ||
...result.hoist_result.dynamic_imports, | ||
]), | ||
} | ||
: undefined, | ||
}; | ||
Comment on lines
+11
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
} | ||
|
||
export {transformWrapper as transform}; |
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]
?