-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bindings/ts): Inline Wasm file into
wasm.js
(#9139)
**Description:** Requested by https://github.com/marco-ippolito/node/pull/2/files#r1665267733
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
set -eu | ||
|
||
./scripts/build.sh | ||
wasm-pack build --out-name wasm --release --scope=swc --target nodejs | ||
npx jest $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
wasm-pack build --debug --scope swc -t nodejs --features getrandom/js $@ | ||
#!/usr/bin/env bash | ||
set -eux | ||
|
||
export CARGO_PROFILE_RELEASE_LTO="fat" | ||
export CARGO_PROFILE_RELEASE_OPT_LEVEL="z" | ||
wasm-pack build --out-name wasm --release --scope=swc --target nodejs | ||
ls -al ./pkg | ||
|
||
node ./scripts/patch.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'node:fs/promises'; | ||
|
||
|
||
const rawWasmFile = await fs.readFile('pkg/wasm_bg.wasm'); | ||
const origJsFile = await fs.readFile('pkg/wasm.js', 'utf8'); | ||
|
||
const base64 = rawWasmFile.toString('base64'); | ||
|
||
const patchedJsFile = origJsFile | ||
.replace(`const path = require('path').join(__dirname, 'wasm_bg.wasm');`, '') | ||
.replace(`const bytes = require('fs').readFileSync(path);`, ` | ||
const { Buffer } = require('node:buffer'); | ||
const bytes = Buffer.from('${base64}', 'base64');`) | ||
|
||
await fs.writeFile('pkg/wasm.js', patchedJsFile); | ||
|
||
// Remove wasm file | ||
await fs.unlink('pkg/wasm_bg.wasm'); | ||
|
||
// Remove wasm from .files section of package.json | ||
const pkgJsonFile = await fs.readFile('pkg/package.json', 'utf8'); | ||
const pkgJson = JSON.parse(pkgJsonFile); | ||
pkgJson.files = pkgJson.files.filter(file => file !== 'wasm_bg.wasm'); | ||
await fs.writeFile('pkg/package.json', JSON.stringify(pkgJson, null, 2)); |
307b6f2
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.
Benchmark
es/full/bugs-1
277530
ns/iter (± 1316
)290444
ns/iter (± 11329
)0.96
es/full/minify/libraries/antd
2068690340
ns/iter (± 66548630
)1919643974
ns/iter (± 39937062
)1.08
es/full/minify/libraries/d3
427297670
ns/iter (± 10527793
)369732041
ns/iter (± 10433843
)1.16
es/full/minify/libraries/echarts
1782403033
ns/iter (± 21631962
)1633511802
ns/iter (± 25080120
)1.09
es/full/minify/libraries/jquery
110711034
ns/iter (± 1613653
)105947919
ns/iter (± 1073274
)1.04
es/full/minify/libraries/lodash
121856807
ns/iter (± 1883026
)116070843
ns/iter (± 1397781
)1.05
es/full/minify/libraries/moment
62759261
ns/iter (± 401796
)60237809
ns/iter (± 516760
)1.04
es/full/minify/libraries/react
19039215
ns/iter (± 103697
)18544967
ns/iter (± 80259
)1.03
es/full/minify/libraries/terser
341682493
ns/iter (± 13840088
)289015517
ns/iter (± 3680925
)1.18
es/full/minify/libraries/three
636074858
ns/iter (± 22958037
)532464539
ns/iter (± 14539340
)1.19
es/full/minify/libraries/typescript
3535337889
ns/iter (± 33966321
)3393879322
ns/iter (± 31340716
)1.04
es/full/minify/libraries/victory
1019700307
ns/iter (± 19897044
)859388278
ns/iter (± 12896313
)1.19
es/full/minify/libraries/vue
160562412
ns/iter (± 1996125
)149384965
ns/iter (± 3610406
)1.07
es/full/codegen/es3
60539
ns/iter (± 164
)61743
ns/iter (± 321
)0.98
es/full/codegen/es5
61459
ns/iter (± 490
)61697
ns/iter (± 392
)1.00
es/full/codegen/es2015
60896
ns/iter (± 420
)61912
ns/iter (± 258
)0.98
es/full/codegen/es2016
61107
ns/iter (± 558
)61978
ns/iter (± 925
)0.99
es/full/codegen/es2017
60855
ns/iter (± 355
)61517
ns/iter (± 420
)0.99
es/full/codegen/es2018
61255
ns/iter (± 454
)62083
ns/iter (± 1865
)0.99
es/full/codegen/es2019
61536
ns/iter (± 395
)61879
ns/iter (± 679
)0.99
es/full/codegen/es2020
60531
ns/iter (± 103
)61971
ns/iter (± 341
)0.98
es/full/all/es3
165173322
ns/iter (± 587926
)162917119
ns/iter (± 1523645
)1.01
es/full/all/es5
159546007
ns/iter (± 405631
)155320780
ns/iter (± 700581
)1.03
es/full/all/es2015
117744203
ns/iter (± 917189
)114913448
ns/iter (± 713962
)1.02
es/full/all/es2016
116652402
ns/iter (± 1328741
)113797638
ns/iter (± 544166
)1.03
es/full/all/es2017
115828027
ns/iter (± 2321375
)113084848
ns/iter (± 763135
)1.02
es/full/all/es2018
113835680
ns/iter (± 878329
)111102906
ns/iter (± 868264
)1.02
es/full/all/es2019
113487523
ns/iter (± 602199
)110682679
ns/iter (± 617166
)1.03
es/full/all/es2020
108667012
ns/iter (± 558434
)106876427
ns/iter (± 1680727
)1.02
es/full/parser
461526
ns/iter (± 3091
)448232
ns/iter (± 2667
)1.03
es/full/base/fixer
15260
ns/iter (± 58
)15225
ns/iter (± 47
)1.00
es/full/base/resolver_and_hygiene
81899
ns/iter (± 332
)79593
ns/iter (± 308
)1.03
serialization of serde
271
ns/iter (± 7
)275
ns/iter (± 3
)0.99
css/minify/libraries/bootstrap
22232929
ns/iter (± 491634
)21936479
ns/iter (± 97063
)1.01
css/visitor/compare/clone
1365448
ns/iter (± 9489
)1353511
ns/iter (± 18952
)1.01
css/visitor/compare/visit_mut_span
1479961
ns/iter (± 22575
)1469416
ns/iter (± 13358
)1.01
css/visitor/compare/visit_mut_span_panic
1492992
ns/iter (± 43582
)1494622
ns/iter (± 42148
)1.00
css/visitor/compare/fold_span
1998134
ns/iter (± 18055
)1984316
ns/iter (± 8419
)1.01
css/visitor/compare/fold_span_panic
2119601
ns/iter (± 3059
)2119241
ns/iter (± 9306
)1.00
css/lexer/bootstrap_5_1_3
3510020
ns/iter (± 27575
)3584321
ns/iter (± 3275
)0.98
css/lexer/foundation_6_7_4
2830925
ns/iter (± 2400
)2906519
ns/iter (± 4083
)0.97
css/lexer/tailwind_3_1_1
548287
ns/iter (± 621
)538160
ns/iter (± 2367
)1.02
css/parser/bootstrap_5_1_3
16142257
ns/iter (± 124520
)15928586
ns/iter (± 29585
)1.01
css/parser/foundation_6_7_4
12847036
ns/iter (± 7496
)12758930
ns/iter (± 37874
)1.01
css/parser/tailwind_3_1_1
2532937
ns/iter (± 6072
)2514324
ns/iter (± 11131
)1.01
es/codegen/colors
723205
ns/iter (± 395543
)729536
ns/iter (± 399819
)0.99
es/codegen/large
2954185
ns/iter (± 1592191
)3050743
ns/iter (± 1603353
)0.97
es/codegen/with-parser/colors
40373
ns/iter (± 1056
)40444
ns/iter (± 164
)1.00
es/codegen/with-parser/large
450111
ns/iter (± 2507
)448522
ns/iter (± 1803
)1.00
es/minify/libraries/antd
1556035566
ns/iter (± 19953000
)1438832597
ns/iter (± 24767526
)1.08
es/minify/libraries/d3
311269941
ns/iter (± 14002778
)289745767
ns/iter (± 12145482
)1.07
es/minify/libraries/echarts
1271524527
ns/iter (± 10723565
)1122852597
ns/iter (± 25491846
)1.13
es/minify/libraries/jquery
83856042
ns/iter (± 812646
)82517539
ns/iter (± 358545
)1.02
es/minify/libraries/lodash
106062425
ns/iter (± 286615
)104080290
ns/iter (± 249885
)1.02
es/minify/libraries/moment
48967298
ns/iter (± 129629
)48248486
ns/iter (± 51682
)1.01
es/minify/libraries/react
16402658
ns/iter (± 61338
)16152015
ns/iter (± 144039
)1.02
es/minify/libraries/terser
234130276
ns/iter (± 3193616
)216390656
ns/iter (± 513870
)1.08
es/minify/libraries/three
415752693
ns/iter (± 9149091
)360324734
ns/iter (± 905676
)1.15
es/minify/libraries/typescript
2908174544
ns/iter (± 39554690
)2630339254
ns/iter (± 14722096
)1.11
es/minify/libraries/victory
687124561
ns/iter (± 23994129
)545029280
ns/iter (± 2706248
)1.26
es/minify/libraries/vue
125026827
ns/iter (± 1194551
)120785971
ns/iter (± 250688
)1.04
es/visitor/compare/clone
1727597
ns/iter (± 21324
)1753108
ns/iter (± 16550
)0.99
es/visitor/compare/visit_mut_span
2156759
ns/iter (± 51195
)2089428
ns/iter (± 28396
)1.03
es/visitor/compare/visit_mut_span_panic
2092305
ns/iter (± 29832
)2099444
ns/iter (± 35948
)1.00
es/visitor/compare/fold_span
2778381
ns/iter (± 7245
)2834028
ns/iter (± 60960
)0.98
es/visitor/compare/fold_span_panic
2852048
ns/iter (± 16530
)2836701
ns/iter (± 44190
)1.01
es/lexer/colors
9490
ns/iter (± 35
)9523
ns/iter (± 75
)1.00
es/lexer/angular
5017920
ns/iter (± 15584
)5116519
ns/iter (± 89296
)0.98
es/lexer/backbone
642690
ns/iter (± 9735
)630410
ns/iter (± 3549
)1.02
es/lexer/jquery
3655353
ns/iter (± 29214
)3613749
ns/iter (± 35358
)1.01
es/lexer/jquery mobile
5620256
ns/iter (± 71086
)5344058
ns/iter (± 31957
)1.05
es/lexer/mootools
2880228
ns/iter (± 34123
)2862085
ns/iter (± 9789
)1.01
es/lexer/underscore
540991
ns/iter (± 9134
)528694
ns/iter (± 1260
)1.02
es/lexer/three
16387885
ns/iter (± 92188
)16263681
ns/iter (± 114870
)1.01
es/lexer/yui
2892301
ns/iter (± 26856
)2907493
ns/iter (± 23784
)0.99
es/lexer/cal-com
13159071
ns/iter (± 612183
)13377768
ns/iter (± 101784
)0.98
es/lexer/typescript
91636924
ns/iter (± 526946
)93673108
ns/iter (± 471174
)0.98
es/parser/colors
23413
ns/iter (± 360
)23545
ns/iter (± 169
)0.99
es/parser/angular
12501227
ns/iter (± 104762
)13439478
ns/iter (± 322269
)0.93
es/parser/backbone
1820893
ns/iter (± 9018
)1835089
ns/iter (± 9165
)0.99
es/parser/jquery
10080518
ns/iter (± 71709
)10388832
ns/iter (± 187625
)0.97
es/parser/jquery mobile
15157022
ns/iter (± 210538
)16224802
ns/iter (± 222844
)0.93
es/parser/mootools
7812212
ns/iter (± 19503
)7937615
ns/iter (± 38401
)0.98
es/parser/underscore
1593610
ns/iter (± 9578
)1602648
ns/iter (± 15183
)0.99
es/parser/three
44697310
ns/iter (± 867289
)47351913
ns/iter (± 504535
)0.94
es/parser/yui
7398709
ns/iter (± 34944
)7533113
ns/iter (± 41515
)0.98
es/parser/cal-com
39490776
ns/iter (± 429206
)42371594
ns/iter (± 456989
)0.93
es/parser/typescript
267700269
ns/iter (± 2230846
)277725641
ns/iter (± 5198669
)0.96
es/preset-env/usage/builtin_type
141391
ns/iter (± 34398
)136543
ns/iter (± 33312
)1.04
es/preset-env/usage/property
17394
ns/iter (± 246
)16156
ns/iter (± 113
)1.08
es/resolver/typescript
97988238
ns/iter (± 2700930
)102716443
ns/iter (± 4237227
)0.95
es/fixer/typescript
82433309
ns/iter (± 1841599
)79697487
ns/iter (± 3143434
)1.03
es/hygiene/typescript
172221570
ns/iter (± 2318823
)172552387
ns/iter (± 2586506
)1.00
es/resolver_with_hygiene/typescript
304014032
ns/iter (± 3698153
)299018894
ns/iter (± 3223204
)1.02
es/visitor/base-perf/module_clone
56385
ns/iter (± 392
)56724
ns/iter (± 450
)0.99
es/visitor/base-perf/fold_empty
59508
ns/iter (± 274
)59851
ns/iter (± 830
)0.99
es/visitor/base-perf/fold_noop_impl_all
59542
ns/iter (± 1412
)60047
ns/iter (± 629
)0.99
es/visitor/base-perf/fold_noop_impl_vec
59118
ns/iter (± 324
)60265
ns/iter (± 1108
)0.98
es/visitor/base-perf/boxing_boxed_clone
62
ns/iter (± 0
)62
ns/iter (± 0
)1
es/visitor/base-perf/boxing_unboxed_clone
47
ns/iter (± 0
)47
ns/iter (± 0
)1
es/visitor/base-perf/boxing_boxed
106
ns/iter (± 0
)107
ns/iter (± 0
)0.99
es/visitor/base-perf/boxing_unboxed
81
ns/iter (± 0
)82
ns/iter (± 0
)0.99
es/visitor/base-perf/visit_contains_this
2588
ns/iter (± 50
)2574
ns/iter (± 31
)1.01
es/base/parallel/resolver/typescript
2487456796
ns/iter (± 116512734
)2508501125
ns/iter (± 136885041
)0.99
es/base/parallel/hygiene/typescript
3254392236
ns/iter (± 58144088
)3243120328
ns/iter (± 60426990
)1.00
babelify-only
494774
ns/iter (± 20105
)493802
ns/iter (± 4464
)1.00
parse_and_babelify_angular
37196429
ns/iter (± 343475
)45122341
ns/iter (± 617537
)0.82
parse_and_babelify_backbone
4340368
ns/iter (± 146357
)4515594
ns/iter (± 220547
)0.96
parse_and_babelify_jquery
29004369
ns/iter (± 410581
)29431163
ns/iter (± 234154
)0.99
parse_and_babelify_jquery_mobile
50614574
ns/iter (± 1083053
)53746501
ns/iter (± 863653
)0.94
parse_and_babelify_mootools
25715385
ns/iter (± 246791
)26850579
ns/iter (± 293320
)0.96
parse_and_babelify_underscore
3662514
ns/iter (± 8100
)3711911
ns/iter (± 60291
)0.99
parse_and_babelify_yui
24313523
ns/iter (± 508815
)25153713
ns/iter (± 305656
)0.97
html/minify/document/css_spec
45347455
ns/iter (± 844079
)46155378
ns/iter (± 165581
)0.98
html/minify/document/github
18175235
ns/iter (± 144195
)18335846
ns/iter (± 35863
)0.99
html/minify/document/stackoverflow
16616657
ns/iter (± 593523
)16757708
ns/iter (± 480318
)0.99
html/minify/document_fragment/css_spec
44088283
ns/iter (± 539654
)44480700
ns/iter (± 1090662
)0.99
html/minify/document_fragment/github
17837422
ns/iter (± 439133
)17995464
ns/iter (± 59423
)0.99
html/minify/document_fragment/stackoverflow
16152177
ns/iter (± 50919
)16267061
ns/iter (± 6450
)0.99
html/document/visitor/compare/clone
168266
ns/iter (± 1503
)166601
ns/iter (± 1948
)1.01
html/document/visitor/compare/visit_mut_span
186163
ns/iter (± 1193
)182604
ns/iter (± 1840
)1.02
html/document/visitor/compare/visit_mut_span_panic
190852
ns/iter (± 1192
)190077
ns/iter (± 1071
)1.00
html/document/visitor/compare/fold_span
235981
ns/iter (± 1505
)232454
ns/iter (± 2421
)1.02
html/document/visitor/compare/fold_span_panic
282953
ns/iter (± 1887
)282064
ns/iter (± 748
)1.00
html/document_fragment/visitor/compare/clone
171859
ns/iter (± 1466
)168531
ns/iter (± 818
)1.02
html/document_fragment/visitor/compare/visit_mut_span
187762
ns/iter (± 1777
)182277
ns/iter (± 970
)1.03
html/document_fragment/visitor/compare/visit_mut_span_panic
191359
ns/iter (± 1343
)187148
ns/iter (± 1499
)1.02
html/document_fragment/visitor/compare/fold_span
234383
ns/iter (± 1955
)232168
ns/iter (± 1815
)1.01
html/document_fragment/visitor/compare/fold_span_panic
283255
ns/iter (± 1512
)282022
ns/iter (± 1439
)1.00
html/lexer/css_2021_spec
12879102
ns/iter (± 54777
)12752234
ns/iter (± 21004
)1.01
html/lexer/github_com_17_05_2022
4924895
ns/iter (± 7833
)4894552
ns/iter (± 12082
)1.01
html/lexer/stackoverflow_com_17_05_2022
4688996
ns/iter (± 127424
)4651680
ns/iter (± 25403
)1.01
html/parser/parser_document/css_2021_spec
25624559
ns/iter (± 200238
)25003075
ns/iter (± 116315
)1.02
html/parser/parser_document/github_com_17_05_2022
8470308
ns/iter (± 14103
)8406505
ns/iter (± 15898
)1.01
html/parser/parser_document/stackoverflow_com_17_05_2022
7481381
ns/iter (± 14122
)7306296
ns/iter (± 20130
)1.02
html/parser/parser_document_fragment/css_2021_spec
25280391
ns/iter (± 76664
)24543117
ns/iter (± 45562
)1.03
html/parser/parser_document_fragment/github_com_17_05_2022
8430956
ns/iter (± 37717
)8310681
ns/iter (± 11841
)1.01
html/parser/parser_document_fragment/stackoverflow_com_17_05_2022
7429603
ns/iter (± 20206
)7280095
ns/iter (± 12504
)1.02
This comment was automatically generated by workflow using github-action-benchmark.