Standard · building, checking, the tests

Performance

The work is many small changes in quick succession, so the time to build and check one is kept like correctness. Each cycle has a budget; the checks time themselves against it and say when they are over; an over-budget cycle is the next task. This page is the budgets, where the time goes now, and how to measure it.

Warm build
under 1 minute
The check, before a merge
under 2 minutes
Everything, before a push
about 10 minutes

The budgets

CycleThe commandBudget
Warm build after an editcargo build --releaseunder 1 minute (seconds is the aim)
The checks, as work goes on and before each mergecargo xtask checkunder 2 minutes (CHECK_BUDGET)
Cold build from a fresh clone or worktreecargo build --release in an empty target folderunder 5 minutes
Everything, before a push or a releasecargo xtask check --fullabout 10 minutes (FULL_BUDGET)

Times are measured on an idle machine (the development Mac: 12 cores, 8 performance and 4 efficiency, 64 GB). Every cargo xtask command is timed against its budget, and so is each step of check. The build is a step of its own, held to the warm build's budget, or the cold build's in a checkout with no release build yet, so the steps after it time only their own work. Each prints its time, a run past its budget prints an OVER BUDGET banner on both streams, and every run (time, worktree, what, seconds, budget) is logged to dt-times.tsv in the git common folder, so every worktree's runs are in one file. The program's build and the tests' build the engine with the same features (no feature is on by default, Manifold's parallelism follows the target, wasm-bindgen is a browser dependency only, insta has no colours, and the program asks for rustix's fs as the tests' tempfile does), so after an engine change the program's build compiles only its own crate (7 s, from rebuilding dt-eval through dharmatiles); dt-crash-switch is the one intended difference. To check after changing a dependency, compare the two builds' --message-format=json artifacts: every crate should have the same features. A check ends with each step's time against its budget on one screen. Its tests run from one queue (xtask/src/lanes.rs): three workers take the test binaries, the slowest of the last run first (each binary’s time is kept in dt-test-times.tsv, beside dt-times.tsv, and printed), so no binary is in a lane by name and one added anywhere finds its place. The three hand-picked lanes it replaced had put every small binary in one lane that summed to about 80 s beside a 55 s tile test. A change selects the packages that depend on what it changed, dev-dependencies included, so a dependency a test needs from above is a cost for every change below it: dt-eval read dt-print only for the PNG renderer in its goldens, which made every change to printing rerun the tile tests, the slowest binary, so the renderer is its own crate (dt-render) and check --plan names the packages whose tests a change selects. The tests are CPU-bound, and the next saving is in what the torture set builds. Measured as CPU, one build at a time, the tile binary’s builds are about 330 CPU-s: 220 are the torture tiles’ own builds (26 tiles, the cliffs, tree, grass and shapes largest, 15 to 22 each), the rest are other builds made by single tests (the weighting test’s cliff and trees, the placement test’s meadow at 32 cells, the floors, the debug probe). A test that needs a family on a second system or at another lattice builds the smallest document with the family in it, from memory, and leaves the heavy tile to a thorough_ test. The budgets are one table, xtask/src/budget.rs, and are raised only by editing it.

Where each cycle stands

CycleMeasuredBudget
Warm build (one crate touched)16 s60 swithin
Cold build82 s300 swithin
cargo xtask check (an element change: its crate and everything that depends on it)103 s120 swithin
dt-eval's warm tests (the torture set)38 spart of the check
cargo xtask check --full298 s600 swithin
dt-eval's full run inside it (warm, thorough, the whole-library sweep)227 s

check --full at its peak holds 22 GB (the sweep's five builds and the thorough tests' at once) and keeps about 10 of the 12 cores busy. The live numbers are the last rows of dt-times.tsv; this table is the state when it was last written.

The tests: a torture set, each tile built once

The tile binary, one run at load 30 to 45 (so the seconds are inflated, the shares are not): 358 user CPU-s, 155 builds. The torture set’s own builds are 103 s of the 354 s of build time summed, the other 251 s are builds made by single tests (84 of them small in-memory documents, 112 s: the same dirt, lift and audit each time). By stage: dirt 20 percent, union 17, audit 13, lift 9, wall 9, cliff 8, grass 7, tree 5. A grass or reeds tile’s union is the largest single stage (grass-flowers: union 7.3 s against grass 2.3). Taken out so far: the placement test at 32, 48 and 128 cells reads only where things stand, so it builds low (no union, no gate). Not yet found: a cut of a third; the dirt’s clod stamping (serial, one atan2 and a few cos and pow for each cell of each lobe) and the union are where the CPU is, and neither can change a byte.

Where a build's time goes

A build is mostly serial: alone on the machine, the biggest library tile (cliffs/2x2-cliff-corner, 22.5 s) keeps 4.6 of the 12 cores busy on average. Its peak resident memory is 7.3 GB; the 2×2 wall curve's 7.1 GB, the 2×2 cliff canyon's 6.3 GB. The aim is a ceiling near 1 GB for a library tile; 1x1-grass peaks at 1.8 GB resident, in the union. Resident is not the live heap: counting every malloc and free of a build (an interposing library) puts the live peak of 1x1-grass at 380 MB (the union stage; 275 MB is the scene going in) and of 2x2-cliff-corner at 3.2 GB (1.4 GB going in), a third to a half of the resident figure, because macOS keeps freed pages resident and the parallel booleans free a lot. The live heap is what a browser needs, one thread with no pages given back, so it is the number to bring to 1 GB: 2x2-cliff-corner is not near it, and a 2×2 cliff in the browser asks for more than the 4 GB a wasm32 module can address.

Library tile, aloneBuildThe stages that take the timePeak memory reached by the end of each stage, MB
cliffs/2x2-cliff-corner21 scliff 10.7 s, audit 3.5, union 2.8, dirt 2.1dirt 186, cliff 3880, lift 3664, union 6999, audit 5983
walls/2x2-wall-curve14 sunion 7.2 s, grass 2.4, audit 2.2, wall 1.3dirt 128, wall 1793, grass 2321, union 7060, audit 6577
ground/2x2-grass-tree14 sunion 6.5 s, tree 2.7, grass 2.5, audit 2.1not measured
cliffs/2x2-cliff-canyon16 sdirt 172, cliff 2922, union 6250, audit 5678
ground/1x1-grass3 sdirt 31, lift 123, grass 413, union 1837, audit 1846

The memory column is stage_peak_mb in the build record: while a build runs, a sampler thread reads the process's resident size every 2 ms (memory-stats: the task's resident_size on macOS), and each stage records the highest reading since the one before. It is the whole process's, so read it from a build run alone, and macOS gives freed pages back late, so a later stage can read as high as an earlier one. In the browser the module's memory size stands in (it never shrinks). The union gives the kernel the scene's solids and keeps none (Scene::union takes them), and a carried Manifold patch (patches/0003) lets the kernel free each input as its merge consumes it, so inputs are no longer held to the end of the union and through the export and the gate; what is left of the union's peak is the merges themselves (the biggest merge holds both its inputs and its result, and the batch merges the smallest pair first), which a different tree shape would change, and the vertex numbering with it. A failed allocation in the kernel stops the build with its stage, its size and, in the browser, the module's memory against the 4 GB limit (patches/0004); before it, Manifold's checks compiled away without exceptions and a null was written through, which the browser showed as "memory access out of bounds". It varies from run to run and is never in a hash, a snapshot or the cache's key.

The cliff's CPU, sampled: about half is Manifold (the booleans that carve each stone and the union), a fifth is ray casting (the relief pass: for each stone and each of its faces, at two angles, a ray grid over the face against the stone's mesh, through obvhs), the rest the element's own code. The cliff dresses its columns in parallel and the stones of one column in order, so one tall column sets how long the stage takes. The union is Manifold's batch boolean over every solid in the scene, in source order.

Things built once

A rock is built in its own frame (dt_kit::Body: meshes with no slots and nothing of the scene) and set down by one rigid move (Body::set_down), whatever builds it. A body is made once for what it is made from (ThingId: the canonical form of the stone's hull and the seed of its grain), kept under its own key from the same key maker as a tile's (dt_store::make_thing_key) on the same store, and counted in the build record (things: built, shared, kept). scatter variants=K makes the placements copies of K variants, each drawn once and built once. What this saves is measured, and it is less than the shape of the idea suggests: a 1x1 cover of 2,000 pebbles a square (pattern=cover, about 3,000 stones) spends its 12 s in the scatter stage on drawing each stone (4.5 s: the hull's cuts and chips), importing each into the kernel (5 s: one mesh import for every copy, since every solid carries a source id of its own, so a copy cannot share its original's) and little on the grain. With variants=12 the draws are made twelve times and the grain twelve times, 22 bodies for 3,593 stones: the scatter stage takes 5.9 s, and the build 10.5 s against 15.0 s. The union (4 s, 2.2 GB resident) and the gate hold every copy and are what they were: copying saves building, never the size of the result, so the peak memory does not fall (it rose, 2.6 GB against 2.2 GB, with 3,593 stones standing against 3,025: the variants' sizes let more of them fit). The next saving is the import: a copy that took its source id without a second import would need the trace to follow two solids with one id. A tile rebuilt after an edit that touches none of its rocks reads them (20 of 20 read, none built in the test document) but the two scatter stages were 0.24 s of that 0.59 s build, so the time saved there is small too. Flowers and trees are built where they stand and are not kept: a flower built at the origin and moved differs by a hair's breadth, which moved 1x1-grass-flowers' union repairs (260 to 308 pinches, over its budget), and a tree's sink into the ground, its footing and its top= read the tile.

The library sweep

The library baseline (crates/dt-eval/tests/tiles/baseline.rs, held to crates/dt-eval/tests/baseline/library-db.tsv) builds every library tile on DungeonBlocks once, on the seed it writes: sixty builds. Its repair budgets were recorded as the worst of four seeds, which leaves room for the counts' noise; the counts are held to them on the one seed. It is CPU-bound: the builds run on WORKERS threads at once, longest first, each build spreading over the machine inside; five fill the machine (the cliff tiles: 300 s on three workers, 251 on five, 250 on six, the same 2,230 s of CPU each), and five of the biggest builds together are 41 GB. The cliff tiles are about half the sweep.

So the sweep is made faster only by building less or by building faster: the engine's own time (the cliff's stones, Manifold's booleans, the relief rays) is what it is made of. cargo xtask sweep grass sweeps only the tiles that use an element; the check sweeps only the library tiles a change touches.

The same tile everywhere

A tile is the same bytes in the browser as in the program, and cargo xtask parity checks it: it builds the wasm bundle, builds a fixed set of twenty tiles (the torture set’s elements on both systems, nine cliff tiles and ground/1x1-grass) under Node and natively through one function, dt-web’s parity_line, and compares each tile’s STL hash and audit numbers (triangles, repairs, volume, the gate’s verdict) as text. Any difference fails it and names the tile and the fields. The browser half is single-threaded, so the tiles are spread over several Node processes and the native half runs beside them: about 45 s with the bundle built (budget 150 s). cargo xtask parity --too-big (about 100 s, apart from the set) holds the other half: a 2×2 cliff in the browser must stop with the stage and the module’s memory in its error, never a memory fault. It is a heavy job (the lock), and runs in check --full and cargo xtask release.

What makes the bytes the same, by construction: Manifold and Clipper2 are compiled with -ffp-contract=off on every target (third_party/manifold-csg-sys), since clang fuses multiply-adds by default on arm64 and WebAssembly has none; glam is built with scalar-math, since its NEON dot and cross products round in another order than its scalar code; obvhs builds its BVH sequentially, since its parallel build lays the tree out differently and a ray that ties at a shared edge would hit another triangle; and every transcendental function is libm’s, which clippy’s disallowed-methods holds. Together they cost the native build under 2 percent. Two more causes were found in the five larger cliff tiles, and both are fixed. (1) glamx’s symmetric 3x3 eigenvalues called std’s acosf and cosf, which differ between the Mac and the browser; parry’s convex hull orders its initial mesh by those eigenvalues, so the same twelve points (a cliff chip) gave the same hull with its triangles in another order. A vendored third_party/glamx (patched in through [patch.crates-io]) calls libm’s. (2) Manifold’s DedupeEdges handed DedupeEdge its duplicate halfedges sorted and unique when it ran in parallel (the program) but in ring-visit order when it ran in series (the browser, and any mesh under 10 000 halfedges), and the order the splits are made in numbers the new vertices, so a big union came out two triangles apart. Found by bisecting Manifold’s parallel policy one algorithm at a time (a runtime mask over every ExecutionPolicy::Par site and the three hand-written TBB loops in edge_op.cpp): only the series dedupe changed the bytes. Carried patch 0002-dedupe-edges-one-order-in-series-and-parallel.patch sorts the series branch too; the parallel code is untouched, so the program’s speed is the same, and the browser’s Manifold takes every patch in third_party/manifold-csg-sys/patches. The seven repair budgets (in six tiles) in the library baseline that the first fix would have raised stay at their earlier values (cliffs/1x1-cliff-corner, 1x1-cliff-spire, 2x1-cliff, 2x2-cliff-corner, 2x2-cliff-massif, 2x2-cliff-plateau), so those tiles fail the baseline test until the cause is lowered.

wasm-opt runs at -Oz. Measured against -O3, the browser build time of a tile is the same (1x1-grass 15.2 s, wall-brick 6.1, fieldstone floor 2.4, in both), since the time is in Manifold’s C++, which clang already optimised; the download is 3.70 MB at -Oz and 3.74 MB at -O3. Nothing is gained from -O3, so -Oz stays.

The page's cards

A full grass tile needs about 2 GB and 20 CPU-seconds, and a wasm heap never shrinks, so a card must never try what a device cannot carry. The cards (docs/assets/live/) keep to these rules; the policy that can be tested without a browser is in limits.js and the tests are web/preview/tests/cards-limits.test.js.

How to measure

To seeRun
A command's wall time and CPU time/usr/bin/time -p <command>: CPU time over wall time is how many cores it kept busy
Its peak memory/usr/bin/time -l <command>: maximum resident set size; per stage, stage_peak_mb in dharmatiles build <tile> --no-cache --json (and in the preview's build message)
A build's stagesdharmatiles build <tile> --no-cache --json: stage_secs, each element of the stack and the union, lift and audit
Where a build's CPU goesstart the build in the background and run sample <pid> 18 1 -file out.txt (macOS): the call tree, and the functions by samples at the top of the stack; leave out the waits (__psynch_cvwait, semaphore_wait_trap, swtch_pri, TBB's backoff) to read the busy share
The sweep at another pool shapeDT_BASELINE_ONLY=cliff (an element's tiles, or lib: paths) on the_library_builds_as_the_baseline_says, with WORKERS changed
Which test spends a test binary’s build timeDT_TEST_TIMES=1 on the tile tests: one TIMES line to stderr per build (the test that asked first, the path, seconds, each stage’s seconds); sum by test, by path or by stage. Seconds are wall seconds, so read them from a quiet machine: at load 40 a plain dirt tile reads 0.9 s that is 0.07 s alone
The browser's tile against the program'scargo xtask parity
The checks' historydt-times.tsv in the git common folder (git rev-parse --git-common-dir)

Measure on an idle machine, one heavy job at a time (the heavy-job lock: cargo xtask heavy <command>), and time the real commands. Find the cause before optimising: load from too many parallel jobs, the same thing built twice, network fetches in builds, and checks sized for the biggest possible change are the usual ones.

Choosing the torture set by coverage

The torture set is the fewest tiles that run the most of the engine. To choose it again (after a new element, say):

  1. Build the program with coverage on the workspace's crates only (instrumenting the dependencies too, Manifold's bindings among them, makes a build four times slower): a RUSTC_WORKSPACE_WRAPPER script that adds -C instrument-coverage, and its own CARGO_TARGET_DIR. The toolchain's llvm-tools component has llvm-profdata and llvm-cov.
  2. Build each test tile once with LLVM_PROFILE_FILE set to a file of its own (and the OpenLOCK and other tiers a test reads), timing each.
  3. For each: llvm-profdata merge, then llvm-cov export -format=lcov, and keep the lines run in the engine's crates (dt-geom, dt-kit, dt-elements, dt-eval, dt-doc, dt-value, dt-lang).
  4. Choose greedily: each time, the tile that runs the most lines the chosen ones do not, per second of building, until the set reaches 99.5% of what all the test tiles run together. Weighting by build time matters: it picks small tiles over big ones that run the same code. Where only a big tile reaches some code, write a small tile that does (that is how 1x1-grove-small and 1x1-reeds came to be) and run the choice again.
  5. Add what line counts cannot see: the odd shapes (a 3×1 zigzag, a 1×2 diagonal, a corner sliver), and a small tile for any feature a warm test reads that no chosen tile has.

A new tile's hash snapshot is checked against a plain build (no observers, the whole machine) before it is committed: that the memo's two-thread, observed build matches it is the proof that threads and observers change nothing.

Rules