Skip to content

Parallelize lg native test compilation and reuse saved core state - #4

Merged
tiensonqin merged 2 commits into
mainfrom
devin/1789994227-parallel-test-compile
Sep 21, 2026
Merged

tiensonqin merged 2 commits into
mainfrom
devin/1789994227-parallel-test-compile

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

dune build @shared/native/runtest cold (rm -rf _build) went from 5m33s to ~40s on this box (~13s with the dune shared cache enabled), all 707 tests passing. Two structural changes on top of the lg fixes in tiensonqin/lg#1:

  • Split the single generated test module into parallel chunks. The test rule previously emitted one ~19.5MB .ml that ocamlopt compiled serially (~44s). Now a base chunk compiles literal + lui + app + lg-test framework off the core library's saved state (emitting include Logseq_chat_lg_core_native), and the 41 test namespaces compile as 8 independent chunks via --compile-files-chunk-from + --emit-state, so ocamlopt runs them in parallel (~3s each).
  • Core rule emits a state (--emit-state logseq_chat_lg_core_native.state), so the test base extends the compiled core instead of recompiling it.
  • The chunk modules live in an unwrapped logseq_chat_lui_test_parts library — dune only emits compile rules for generated modules listed on a library — and the runner executable uses -linkall so test-registration initializers survive dead-stripping.
  • Replaced (:include lg_native_cmi_deps.sexp) dep lists (whose targets were never built) with an lg-native-cmi-deps alias that actually builds the vendored duniverse cmis before lg runs — otherwise lg's typecheck falls back to same-named opam cmis and fails with inconsistent assumptions.
  • Bumps the lg/lg-test pin-depends to the revision with saved-state provenance keys + chunk --emit-state (Make the compile prefix cache survive cold builds; parallelize the clojure-suite smoke tiensonqin/lg#1). If that PR is rebased on merge, this pin must be updated to the merged SHA.

Verification

dune build @shared/native/runtest: 707/707 tests pass; cold rm -rf _build wall time ~39.5s, warm no-op ~0.9s, ~12.7s with (cache enabled) in ~/.config/dune/config (11.6s of which is the test run itself — a user rule, not cached).

Note for environments

The ~13s path requires the dune shared cache. It is off by default; enable per machine via ~/.config/dune/config:

(lang dune 3.24)
(cache enabled)

Link to Devin session: https://app.devin.ai/sessions/ef32b286005d4d049cc1affebba0aab3
Open in Devin Desktop: https://app.devin.ai/desktop/session/ef32b286005d4d049cc1affebba0aab3?variant=devin
Requested by: @tiensonqin

- Replace the single 19.5MB generated test module with a base chunk
  (literal + lui + app + lg-test framework, chained off the core
  library's saved state) plus 8 independent test-namespace chunks, so
  ocamlopt compiles them in parallel instead of one giant unit.
- Emit a saved state from the core library rule (--emit-state) so the
  test base chunk can extend it without recompiling the core directory.
- Compile the chunk modules in an unwrapped native library and force
  them into the link with -linkall so test-registration initializers
  survive dead-stripping.
- Replace the broken (:include lg_native_cmi_deps.sexp) dep lists with
  an lg-native-cmi-deps alias that actually builds the vendored duniverse
  cmis, so lg does not fall back to same-named opam cmis.
- Bump the lg/lg-test pin to the revision carrying saved-state
  provenance keys, interface dedup, and chunk --emit-state support.

Cold 'rm -rf _build' dune build @shared/native/runtest: 5m33s -> ~40s
on this machine, and ~13s with a warm dune shared cache.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Runs 'dune build @shared/native/runtest' on Ubuntu with OCaml 5.5.
Vendored deps are restored from the committed opam-monorepo lockfile
(public dirs) plus clones of the private pin-depends repos (lg, lui,
signal-lg, datascript-ocaml, mldoc, persistent-sorted-set-ocaml) at their
pinned commits.

Cached layers:
- setup-ocaml caches the opam switch (compiled compiler + deps);
- duniverse is cached on the lockfile/opam hash;
- ~/.cache/dune (dune shared cache, enabled via ~/.config/dune/config)
  and .lg-cache are cached per-ref with a main fallback, keeping cold
  'rm -rf _build' runs in the ~13s range after the first warm run.

Requires the repo secret LOGSEQ_GITHUB_PAT (read access to the private
logseq OCaml repos).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@tiensonqin
tiensonqin merged commit bcd6734 into main Sep 21, 2026
1 check failed
@tiensonqin
tiensonqin deleted the devin/1789994227-parallel-test-compile branch September 21, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant