Repository navigation
Commit 9675b32
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`).
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), and emit a warning when a system library `__deps` entry
is redundant with an auto-detected dependency. Also log auto-detected
dependencies in debug/verbose mode (`-sVERBOSE`).
Remove all `autoAddDeps` calls and redundant `__deps` entries across
`src/lib/*.js`. Also fix an unoptimized code size regression (~1 KB in
`test_unoptimized_code_size`) where `wrapSyscallFunction` previously
used a substring check (`t.includes('SYSCALLS')`) that matched a
comment in `fd_write` even when `SYSCALLS_REQUIRE_FILESYSTEM=0`.
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)
Fixes: #190981 parent 7b3808c commit 9675b32
108 files changed
Lines changed: 585 additions & 1953 deletions
File tree
- site/source/docs/porting/connecting_cpp_and_javascript
- src
- lib
- test
- codesize
- jslib
- tools
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
| 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