Repository navigation
Commit c0c9d9f
committed
Automate JS-to-JS library dependencies using Acorn
Replace `addImplicitDeps` and `checkDependencies` in `src/jsifier.mjs`
with `calculateDeps`, which uses `acorn.tokenizer` to automatically
detect references to JS library symbols (`$foo` and `_bar`).
Because `calculateDeps` uses a flat token scan rather than a full AST
and scope analysis pass (both for speed and to support partial JS
fragments in `--pre-js`/`--post-js`), this scanning is conservative and
can include false positives if local variables or parameters shadow a
library symbol name.
Keep the `__deps` mechanism in place for dependencies that static JS
token scanning cannot detect (such as native Wasm/C symbols, function
callbacks in `__deps`, side-effect-only dependencies, and `__postset`
dependencies). Also log auto-detected dependencies in debug/verbose
mode (`-sVERBOSE`).
Performance cost (median of 15 runs on `test/hello_world.c`):
- `tools/compiler.mjs` (`INCLUDE_FULL_LIBRARY=0`):
178.8 ms -> 185.1 ms (+6.3 ms, +3.5% slower)
- `tools/compiler.mjs` (`INCLUDE_FULL_LIBRARY=1`):
268.2 ms -> 343.1 ms (+74.9 ms, +27.9% slower)
- `tools/compiler.mjs --symbols-only`:
181.4 ms -> 254.2 ms (+72.8 ms, +40.1% slower)
- Full `emcc` link (`hello.o` -> `out.js`, cold JS cache):
- `INCLUDE_FULL_LIBRARY=0`: 661.7 ms -> 740.8 ms (+79.1 ms, +12.0%)
- `INCLUDE_FULL_LIBRARY=1`: 758.3 ms -> 906.0 ms (+147.7 ms, +19.5%)
- Full `emcc` link (`hello.o` -> `out.js`, warm JS cache):
- `INCLUDE_FULL_LIBRARY=0`: 271.8 ms (+0.0 ms, 0% slower)
- `INCLUDE_FULL_LIBRARY=1`: 282.4 ms (+0.0 ms, 0% slower)
See: #190981 parent cc1b638 commit c0c9d9f
6 files changed
Lines changed: 236 additions & 120 deletions
File tree
- site/source/docs/porting/connecting_cpp_and_javascript
- src
- test
- jslib
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
597 | 596 | | |
598 | 597 | | |
599 | 598 | | |
| |||
0 commit comments