The budgets
| Cycle | The command | Budget |
|---|---|---|
| Warm build after an edit | cargo build --release | under 1 minute (seconds is the aim) |
| The checks, as work goes on and before each merge | cargo xtask check | under 2 minutes (CHECK_BUDGET) |
| Cold build from a fresh clone or worktree | cargo build --release in an empty target folder | under 5 minutes |
| Everything, before a push or a release | cargo xtask check --full | about 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
| Cycle | Measured | Budget | |
|---|---|---|---|
| Warm build (one crate touched) | 16 s | 60 s | within |
| Cold build | 82 s | 300 s | within |
cargo xtask check (an element change: its crate and everything that depends on it) | 103 s | 120 s | within |
| dt-eval's warm tests (the torture set) | 38 s | part of the check | |
cargo xtask check --full | 298 s | 600 s | within |
| 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
- A test never builds what a test already built. dt-eval's integration tests are one test binary (
crates/dt-eval/tests/tiles/, a module for each file) and build only through one memo (memo::build, from the dev cratedt-testkit), keyed by everything a build reads: the source's content, the path, every field ofOptions. A scan test fails a build outside it unless a// fresh: whycomment says the test must build again (the cache, thread counts, a build compared with itself). - The warm check builds the torture set only.
golden::TILESincrates/dt-eval/tests/tiles/golden.rs: about thirty small test tiles, each held to its stage hashes, repair counts and the gate's verdict. A warm test that reads any other test tile fails, by construction (the memo checks the test's name). A test that needs another tile is athorough_test: ignored, with a reason saying so, and run bycheck --full. --fullruns dt-eval once. Its warm tests, its thorough tests and the library baseline (the sweep) are one run of the one test binary, so a tile any of them reads is built once even there. Only the release gate (every library tile on both systems, whichcargo xtask releaseruns) and a measurement are left out (NOT_CHECKSinxtask/src/work.rs).- Any run at another seed.
DT_TEST_SEED=N(oncargo xtask check,sweeporcargo test) builds every tile a test builds on seed N, unless the test sets a seed itself; the snapshots and the library baseline, recorded at each tile's own seed, are then held only to the gate's pass or fail and the repair budgets, and a baseline rewrite is refused. The library at seed 9001 takes the sweep's time again (about two minutes), not four times the library. - Test builds run several at once. A memo build runs on its own two-thread pool (so the pool is never the whole machine, and a match with the golden hashes, recorded from plain builds, proves threads change nothing), and
memo::prebuildbuilds a list of tiles six at a time.
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, alone | Build | The stages that take the time | Peak memory reached by the end of each stage, MB |
|---|---|---|---|
cliffs/2x2-cliff-corner | 21 s | cliff 10.7 s, audit 3.5, union 2.8, dirt 2.1 | dirt 186, cliff 3880, lift 3664, union 6999, audit 5983 |
walls/2x2-wall-curve | 14 s | union 7.2 s, grass 2.4, audit 2.2, wall 1.3 | dirt 128, wall 1793, grass 2321, union 7060, audit 6577 |
ground/2x2-grass-tree | 14 s | union 6.5 s, tree 2.7, grass 2.5, audit 2.1 | not measured |
cliffs/2x2-cliff-canyon | 16 s | dirt 172, cliff 2922, union 6250, audit 5678 | |
ground/1x1-grass | 3 s | dirt 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.
- The cost is said before the build.
check_tilereturnsfullCost(peak MB and CPU seconds), made bydt_eval::full_costfrom the checked tile: the element schema’sCost(mb,mb_per_square,cpu,cpu_per_square; a thing in a scatter weighs its own, times the scatter’s count or density) added up, an element at a region taken to cover 40 percent of the tile. The weights are fitted tostage_peak_mband CPU seconds on 14 library tiles, andcost::tests::the_estimate_holds_to_measurementsholds the estimate within 2.1 times (memory) and 2.5 times (time) of the measured table, both ways; every row but the clod-less flat tile is within 1.9. Remeasure the table when an element changes much. The Full detail button shows it (“Full detail · about 2 GB, 20 s”). - A device that cannot carry it is told so. From
navigator.deviceMemorywhere the browser gives it (a tab past 40 percent of the device’s memory is the one the system stops), else a phone (coarse pointer, screen 820 px or less) is taken to carry about 1 GB. The button turns off, the cost stays on it, and a note points to the draft shown and to the program on a desktop.deviceMemorychooses the default and the wording only. - Bytes, not counts. The engine’s result cache holds 64 MB (
ByteCache), and a full build is never kept: the card that shows it holds it. - A fresh worker after every full build, so the heap goes back to its floor (a draft is about 70 MB). A build is stopped, and the card told, at three times its estimate (30 s at least, 240 s at most).
- Drafts build through their card’s step cache in the worker (
build_tiletakes a card; four cards at most, the oldest dropped; none for a full build; all gone with the worker), so editing grass on a cliff does not carve the cliff again. - The engine’s files carry their hashes (
cargo xtask wasmwritesdt_web.<hash>.js,dt_web_bg.<hash>.wasm,library.<hash>.jsonandengine.json, read fresh each visit), so an old glue never meets a new module, and the Cache API keeps them under the engine’s hash (caches of other engines are removed): the second visit skips the download. - Drafts are kept between visits by the engine’s own store of kept builds (the one the editor’s worker keeps its full builds in), for the page’s unedited examples only, never a full build. The engine decides the key (dt-store’s, over the document, everything it read, the options and the engine’s hash), the size limit (256 MB, the least recently used out first) and what goes; one file of JavaScript holds its entries in IndexedDB and gives them back at the next start (entries of another engine are dropped when they load). The store is a convenience: when IndexedDB fails the worker keeps its builds in memory and says so on the console.
- A finger scrolls the page. On a touch screen a card turns the tile only after Turn it is pressed, because one finger is the page’s before it is the card’s, and counting fingers goes wrong with the browser’s pinch-zoom and a thumb resting on the glass. A mouse or trackpad turns it by dragging, as before.
- A failed engine start does not strand the line: each waiting card is told in its turn.
How to measure
| To see | Run |
|---|---|
| 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 stages | dharmatiles build <tile> --no-cache --json: stage_secs, each element of the stack and the union, lift and audit |
| Where a build's CPU goes | start 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 shape | DT_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 time | DT_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's | cargo xtask parity |
| The checks' history | dt-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):
- 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_WRAPPERscript that adds-C instrument-coverage, and its ownCARGO_TARGET_DIR. The toolchain'sllvm-toolscomponent hasllvm-profdataandllvm-cov. - Build each test tile once with
LLVM_PROFILE_FILEset to a file of its own (and the OpenLOCK and other tiers a test reads), timing each. - For each:
llvm-profdata merge, thenllvm-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). - 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-smalland1x1-reedscame to be) and run the choice again. - 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
- An over-budget cycle is the next task, straight after the current one and ahead of the queue. It is fixed where the waste is made, never by skipping a check or loosening the gate.
- Slowness is visible by construction: every command and every step of a check is timed against its budget and says when it is over.
- Checks are sized to the change while working (
cargo xtask check); the full set runs once before a push (--full). - A card never tries a full build its device cannot carry, never keeps one in memory after it is shown, and replaces the worker that made one (see the page’s cards).
- At most two heavy jobs on the machine at once: two agents, and the heavy-job lock for sweeps, contact sheets, pictures and the browser build.
- A warm test reads only the torture set; a new element or feature gets a small torture tile, and its test reads that.