Skip to content

Js_of_ocaml: share standalone runtimes#13621

Merged
rgrinberg merged 3 commits intoocaml:mainfrom
vouillon:jsoo-shared-runtime
Mar 17, 2026
Merged

Js_of_ocaml: share standalone runtimes#13621
rgrinberg merged 3 commits intoocaml:mainfrom
vouillon:jsoo-shared-runtime

Conversation

@vouillon
Copy link
Copy Markdown
Member

At the moment, in separate compilation mode, we are building one custom runtime per executable, even though the same runtime could be used by the different executable.

The first commit implement the sharing at the level of a stanza, while the second commit extends it to workspace-wide sharing.

I'm not completely sure the added complexity is worth it. A clean run of the Js_of_ocaml test suite go from 3 minutes down to 2m40 with this change, but it's kind of extreme.

@hhugo What do you think?

@hhugo
Copy link
Copy Markdown
Collaborator

hhugo commented Feb 12, 2026

I wanted to explore another direction where we would emit a minimal runtime based on requirement from individual units. Either having jsoo link do the job of computing the runtime or relying on an intermediate runtime file like now. But we need to make sure the overhead is acceptable (We need incremental rebuilds to be as fast as possible)

That said, I like the current PR.
In the jsoo repo, the size of all runtime files under _build/ goes from ~280M to ~9M with this PR.
We can always revisit later if needed.

@vouillon vouillon marked this pull request as ready for review February 12, 2026 13:32
Comment thread test/blackbox-tests/test-cases/jsoo/jsoo-config.t/run.t Outdated
@vouillon vouillon force-pushed the jsoo-shared-runtime branch 3 times, most recently from 42ab11e to 8025dad Compare March 3, 2026 13:27
@vouillon vouillon force-pushed the jsoo-shared-runtime branch from 8025dad to 8f9ac22 Compare March 12, 2026 13:12
@hhugo
Copy link
Copy Markdown
Collaborator

hhugo commented Mar 13, 2026

@rgrinberg, I think this is ready

@hhugo hhugo added the jsoo label Mar 13, 2026
@hhugo
Copy link
Copy Markdown
Collaborator

hhugo commented Mar 14, 2026

@vouillon, this needs to be rebased

When dune builds `(executables (names a b c))` in separate compilation
mode, it previously ran `js_of_ocaml build-runtime` once per executable.
Since all executables in the same stanza share the same compilation
context, the runtimes are identical. This change builds one shared
runtime per stanza per mode, eliminating redundant work.

Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Phase 1 shared one runtime per (executables ...) stanza. This commit
eliminates remaining duplication by sharing runtimes across all stanzas
in the workspace that link the same set of runtime-contributing libraries.

Following the PPX driver sharing pattern (Key module + on-demand rule
generation), a Runtime_key module encodes (mode, lib_names, project_root)
into a digest. Stanzas with no user javascript_files/wasm_files get a
Shared digest; others keep per-stanza behavior.

Shared runtimes are built on-demand at .js/<config>/.runtime/<digest>/
when first requested, with the config resolved dynamically at build time
to ensure correctness across directories with different env configs.

Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Use dune trace cat | jq to extract deterministic sorted target lists
instead of --display short which produces unstable build step ordering.
For install tests, use find | sort instead of install log output.

Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
@vouillon vouillon force-pushed the jsoo-shared-runtime branch from 8f9ac22 to 88620d2 Compare March 17, 2026 10:41
@rgrinberg rgrinberg merged commit b0bfad0 into ocaml:main Mar 17, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants