Skip to content

Re-enable the PrecompileTools workload to cut cold discretize latency - #727

Open
xtalax-droid wants to merge 1 commit into
SciML:masterfrom
xtalax-droid:forge/cold-latency
Open

xtalax-droid wants to merge 1 commit into
SciML:masterfrom
xtalax-droid:forge/cold-latency

Conversation

@xtalax-droid

Copy link
Copy Markdown

Problem

The PrecompileTools workload in src/precompile.jl has been disabled (if false) since the compat update, so every fresh Julia process paid roughly 40-60 s of compilation on the first discretize call, plus 8-13 s for mtkcompile and 5-27 s for ODEProblem. Warm calls take milliseconds, so this is almost entirely inference and codegen. A SnoopCompile profile showed the time spread over hundreds of Base, SymbolicUtils and ModelingToolkit specializations rather than any single MOL hot spot, so re-enabling the workload was preferred over targeted edits.

Fix

The workload is rewritten and re-enabled. It runs discretize, symbolic_discretize, mtkcompile and ODEProblem on:

  • 1D diffusion with a Dirichlet left and Neumann right boundary.
  • 1D advection-diffusion, periodic, with UpwindScheme and WENOScheme.
  • A 2D two-variable periodic reaction-diffusion system.

Periodic systems use should_transform = false so precompilation stays quiet (periodic boundaries are interfaces, so the transformation is skipped for them regardless). No new dependencies; PrecompileTools was already in [deps] and [compat].

Results

Cold = first call in a fresh process. Median of 3 fresh processes, Julia 1.12.1, 32-core box with some load from other jobs.

system discretize mtkcompile ODEProblem first solve
heat1d_dirichlet_neumann 41.4 -> 0.64 s 8.1 -> 0.06 s 5.3 -> 0.51 s 5.1 -> 5.1 s
weno_advection1d 51.7 -> 0.88 s 10.6 -> 0.29 s 6.6 -> 2.04 s 13.7 -> 11.6 s
brusselator2d N=32 61.1 -> 4.71 s 12.6 -> 2.3 s 27.1 -> 18.4 s 14.2 -> 11.7 s

Cost: package precompile goes from about 9 s to about 87 s wall, and the MethodOfLines cache from 4.5 MB to 139 MB. If that is too much, the 2D case is the first thing to drop (about 4 s of brusselator discretize).

What remains is compile time of the generated RHS (ODEProblem and first solve). That lives in ModelingToolkit, RuntimeGeneratedFunctions and OrdinaryDiffEq and is not addressed here.

Tests

GROUP=Components and GROUP=QA (21/21) pass on the final commit; Runic is clean.

Review notes

  • The workload runs at precompile time, so an API change that makes a workload system throw breaks using MethodOfLines, not just a test.
  • Coverage is the systems above; staggered grids, pseudospectral, 3D and higher orders still compile cold.

🤖 Posted by an AI agent · harness: Claude Code 2.1.309 · model: claude-sonnet-5-5
Review: unreviewed
Session: 47ff55ef-8952-4078-8e4e-77c72c85d6c4

The workload was disabled behind if false during the compat update, so every first discretize/mtkcompile/ODEProblem paid ~40-60 s of inference. It now covers 1D Dirichlet/Neumann, periodic upwind and WENO, and a 2D periodic system, each through discretize, symbolic_discretize, mtkcompile and ODEProblem. Periodic systems pass should_transform=false so precompilation does not warn about interface boundaries.

Agent-Harness: Claude Code 2.1.309
Agent-Model: claude-sonnet-5-5
Agent-Session: 47ff55ef-8952-4078-8e4e-77c72c85d6c4
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>

This branch has not been deployed

No deployments
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.

2 participants