Skip to content

Add Perf gates for assembly time and allocations - #9

Merged
xtalax merged 3 commits into
masterfrom
forge/m1-5-perf-gate
Oct 28, 2026
Merged

xtalax merged 3 commits into
masterfrom
forge/m1-5-perf-gate

Conversation

@xtalax-droid

Copy link
Copy Markdown
Collaborator

The M3 performance and allocation gate (spec §6.6 items 1, 3 and 4; §10.6). Stacked on #7 (base forge/m1-4-integration).

What

A new Perf test group, test/Perf/perf.jl, runs on Julia 1 only and checks three gates on 100×100 P1 triangles.

  1. Linear assembly time. Case (i) goes through the whole generated pipeline (stand-in analyse, weak_form, emit_kernels, then assemble_linear! in place). It must take at most 3× as long as a hand-written Ferrite loop. This is checked with and without the Neumann and Robin facets, and the operators must also agree with the hand-written ones to 1e-14.
  2. Allocations. The amount allocated per pass by the linear and nonlinear passes must not depend on mesh size; this is checked by comparing a 20×20 mesh with a 100×100 one. AllocCheck must also find no allocations in the per-cell element, facet and gather functions.
  3. Nonlinear assembly time. The case (iii) residual and Jacobian for one Newton step must take at most 3× as long as a hand-written r and J loop, and must agree with it to 1e-13.

AllocCheck is added as a test-only extra.

Driver fixes

The gates found two problems in the driver, and Codex review found a third.

  • Per-facet allocation in the nonlinear pass. Generated tangents return a literal Int 0 for constant-zero entries. Indexing that mixed tuple allocated at every facet quadrature point, so the nonlinear pass grew from 8.8 kB to 124 kB between 20×20 and 100×100. The tangent tuple is now promoted to one type.
  • Facet lookups on interior cells. AssemblyContext now records which cells touch any boundary piece, and interior cells skip the facet membership lookups. This took the facet case from 2.42× to 1.68×.
  • Stale facet-cell cache. AssemblyContext now copies each facet set when it is built. Later changes to the caller's set cannot get out of step with the cached cell list. This is documented in the docstring, and a regression test covers it.

Measured on 100×100 P1

Minimum of 10 runs, with both sides assembling in place.

Case Hand-written Generated Ratio
(i), volume terms 2.90 ms 4.68 ms 1.61×
(i), with Neumann and Robin facets 2.88 ms 4.84 ms 1.68×
(iii), r and J 2.44 ms 2.98 ms 1.22×

Allocations per pass are 12.5 kB for the linear pass and 8.9 kB for the nonlinear pass, the same at 20×20 and 100×100.

Tests

Group Result
Perf 20/20, 63 s
Assembly 24/24
Integration passes
QA 20/20

Runic and typos are clean. Codex approved it in round 2; round 1's finding was the stale facet-cell cache.

Branches covered: spec §6.6 items 1 and 3, with and without facets. Item 4, the performance of the one-pass nonlinear r and J. The §10.6 "within 3×" and "allocation-free under AllocCheck" gates. Construction time at N = 1e4 belongs to the DAE lowering in M2 and M3.

Reviewer notes

  • The timing gates run on shared CI runners. The measured ratios are at least 1.8× below the gate, and both sides take the minimum of 10 runs, but a badly overloaded runner could still flake.
  • The AllocCheck targets are driver internals, so renaming them breaks the Perf test. That is intended.

🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-opus-5-5
Review: unreviewed
Session: d6252e53-ed42-4149-9811-233262edb2ef

xtalax and others added 3 commits October 26, 2026 16:38
Generated tangents return a literal Int 0 for constant-zero entries; indexing the resulting mixed tuple with a runtime index allocated on every facet quadrature point (nonlinear pass grew from 8.8 kB at 20x20 to 124 kB at 100x100). Promoting the tuple makes it homogeneous. The context now also records which cells touch any piece, so interior cells skip the per-facet Set lookups (case (i) with facets: 2.4x to 1.7x of hand-written).

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Spec §6.6 items 1, 3, 4 and §10.6: case (i) linear assembly and case (iii) residual and Jacobian on 100x100 P1 within 3x of hand-written Ferrite loops (minimum of 10 runs after warm-up), per-pass allocations independent of mesh size (20x20 vs 100x100), and AllocCheck on the per-cell element, facet and gather functions. AllocCheck is a new test-only extra. Runs on Julia 1 only.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
The cached facet-cell membership went stale when a caller mutated a facet set it had passed in: assembly skipped the new facet and the facet-count assertion threw. The context now copies every facet set into a Set{FacetIndex} at construction, so later mutations of the caller's set or of the grid's facet sets cannot desynchronise it.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: d6252e53-ed42-4149-9811-233262edb2ef
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
@xtalax-droid
xtalax-droid changed the base branch from forge/m1-4-integration to forge/m1-3-assembly October 26, 2026 21:03
@xtalax-droid
xtalax-droid changed the base branch from forge/m1-3-assembly to master October 27, 2026 23:43
@xtalax
xtalax merged commit a9c8eb7 into master Oct 28, 2026
5 checks passed
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