Skip to content

test: the profiling crate, thrust-profiling, with the v1 router's heap profile (test-suites PR 4) - #267

Merged
aRustyDev merged 3 commits into
mainfrom
test/profiling-heap
Nov 17, 2026
Merged

aRustyDev merged 3 commits into
mainfrom
test/profiling-heap

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

PR 4 of the test-suites plan (.agents/plans/test-suites/): the first profiling workload, which the owner chose to be the in-process v1 router, and its heap profile. crates/testing/profiling is a new crate, thrust-profiling.

What

  • src/lib.rs, the workload. run sends a mix of creates, lists, searches and updates through the v1 router with tower's oneshot. There is no server and no network, so the profiler sees the application's own work. A ballast of bytes held during the run exists for the control.
  • tests/common/mod.rs, the world the workload runs against. It serves the real v1 routes over thrust-core and the memory adapters, and is deterministic: a fixed clock, counter ids and randomness, a cheap argon2id, and background work dropped. It lives in tests/ and not in the library because it mints SystemScope. In my first draft it was in src/, and check-deps.sh's proof-minting guard refused it (feat(core): make Scope the argument of every repository and Tx method #35, feat(compat): the 48-route minimum slice with the auth-client JSON change #44). Its shape is the same as crates/api/v1/tests/common.
  • tests/heap.rs installs dhat-rs as that test binary's global allocator.
    • prof_heap_router profiles the 320-request mix. It prints the totals and writes target/profiling/dhat-heap-router.json for dhat's viewer.
    • prof_heap_counts_a_known_extra_allocation is its control (below).
  • tests/workload.rs checks every request of a generated mix (prop_) and of the profiled mix. Each must be answered with a 2xx, so a profile is never one of error paths. These tests are hermetic and run in the default loop.
  • .config/nextest.toml gains a prof profile: one test at a time, output shown on a pass, and no kill. dhat records a backtrace per allocation, so the router's profile takes about 26 s. The default loop leaves out only this crate's prof_ tests, because they write outside a temp dir (AGENTS.md rule 6).
  • release-plz.toml: the crate joins the version group and the changelog, with the first-release tag pattern.
  • Docs:
    • AGENTS.md rule 4 gains prof_.
    • crates/testing/README.md gets a row and a description for profiling/.
    • performance.md describes the profile and its control.
    • crates.md now counts twenty-one crates.
    • ARCHITECTURE §2a gains a profiling/ line.
    • The plan records PR 3 as merged, and PR 4's status with what was measured.

dhat 0.3.3 is MIT OR Apache-2.0. It is a dev-dependency only, so it is in no shipped graph. Run the profile with:

cargo nextest run -p thrust-profiling --profile prof

The profile

320 requests (200 creates, 50 lists, 20 searches, 50 updates) allocate 128.8 MB in 1.03 M blocks. The peak is 1.58 MB in 14,404 blocks, and 612 KB is still held at the end. No number gates yet (X19).

Evidence

Every check below has a control that makes it fail (AGENTS.md rule 8).

Check Result Control
cargo nextest run -p thrust-profiling (default profile) 2 passed, the 2 prof_ tests skipped
cargo nextest run -p thrust-profiling --profile prof the 2 prof_ tests, both passed; the workload's 2 tests skipped; the dhat file is written (468 KB)
the control, on fresh worlds and a smaller mix two runs without ballast allocate 8,208,890 bytes each; 4 MiB of ballast adds exactly 4,194,304 ballast taken out of the workload: exit 100, "4194304 bytes of ballast added 0 bytes"
the control's first draft it asked a 320-request mix for exact equality and failed on a 758-byte difference between identical runs; it now allows 1% of the ballast
scripts/check-deps.sh exit 0 refused the first draft: "a proof minted outside its owner", SystemScope::mint() in src/lib.rs
cargo mutants -p thrust-profiling 20 mutants, 20 caught The first run, with the world in src/, missed 21. All of them were in the world's fixtures: the clock, ids, rng, config fields and seed fields. Moving the world to tests/common/ for check-deps took them out of scope, as .cargo/mutants.toml excludes **/tests/common/** in every crate. They were not killed by tests. The workload itself was caught in full both times
cargo nextest run --profile ci --workspace (before merging main) 4,641 passed
cargo clippy -p thrust-profiling --all-targets -D warnings, cargo fmt --check, cargo deny check exit 0
every command of CI's deps and ci-scripts jobs, read from ci.yml, shell scripts under dash, after merging today's main 58 of 58 check-release-plz.py refuses a crate that is not declared, as it did for #262
scripts/check-layout.sh 21 crates
cargo metadata --locked after merging main (a crate-adding PR) exit 0
the crate's tests and the prof profile, rerun after merging main (#263 refactored the router's error types) pass

Cargo.toml and .config/ changed, so CI runs everything. The prof profile is not in CI; the CI-split plan owns the workflows.

🤖 Generated with Claude Code

aRustyDev and others added 3 commits November 17, 2026 00:03
…its heap profile with dhat

PR 4 of the test-suites plan, the owner's choice of first workload.
crates/testing/profiling is one crate, thrust-profiling:

- src/lib.rs: the workload. `run` sends a mix of creates, lists,
  searches and updates through a router with tower's oneshot, with no
  server or network. A `ballast` of bytes to hold while it runs is there
  for the control.
- tests/common/mod.rs: the world it runs against, the real v1 routes
  over thrust-core and the memory adapters, deterministic (fixed clock,
  counter ids and randomness, a cheap argon2id). It is in tests/, as
  crates/api/v1/tests/common is, because it mints SystemScope: the
  first draft had it in src/, and check-deps.sh's proof-minting guard
  refused it. That also puts the fixture under mutants.toml's
  **/tests/common/** exclusion, like every crate's harness.
- tests/heap.rs installs dhat-rs as that binary's global allocator.
  prof_heap_router profiles the 320-request mix and writes
  target/profiling/dhat-heap-router.json for dhat's viewer: 128.8 MB in
  1.03 M blocks, peak 1.58 MB. prof_heap_counts_a_known_extra_allocation
  is its control, on fresh worlds: two runs without ballast allocate the
  same bytes, and 4 MiB of ballast adds exactly 4 MiB. With the ballast
  taken out of the workload, the control fails ("added 0 bytes").
- tests/workload.rs: every request of a generated mix is answered with
  a 2xx, in the default loop, so a profile is never one of error paths.
- .config/nextest.toml: a `prof` profile (one test at a time, output
  shown on a pass, no kill: dhat records a backtrace per allocation, so
  the profile takes about 26 s). The default loop leaves out only the
  prof_ tests, which write outside a temp dir (AGENTS.md rule 6).
- release-plz.toml: the crate joins the version group and the changelog,
  with the first-release tag pattern.

dhat 0.3.3 is MIT OR Apache-2.0; it is a dev-dependency, in no shipped
graph.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENTS.md rule 4 gains the `prof_` prefix. crates/testing/README.md: a row
for `profiling/`, and what the crate is (one crate, a group only if two
workloads conflict). docs/src/testing/techniques/performance.md: the heap
profile and its control. docs/src/contributing/crates.md: twenty-one
crates. ARCHITECTURE §2a gains `profiling/`. The plan: PR 3 merged, PR 4's
status, and what was measured.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​dhat@​0.3.310010093100100

View full report

@aRustyDev
aRustyDev enabled auto-merge (squash) November 17, 2026 05:22
@aRustyDev
aRustyDev merged commit cf23669 into main Nov 17, 2026
41 checks passed
@aRustyDev
aRustyDev deleted the test/profiling-heap branch November 17, 2026 05:27
aRustyDev added a commit that referenced this pull request Nov 17, 2026
…pper script (test-suites PR 5) (#272)

* test: the v1 router's CPU profile, under samply through a nextest wrapper script

PR 5 of the test-suites plan, the last.

- crates/testing/profiling/tests/cpu.rs: prof_cpu_router runs the
  profiled mix 20 times on fresh worlds (6,400 requests, about 2 s in
  the release build), with the system allocator. It refuses to run
  without THRUST_PROF_SAMPLY, which only the wrapper sets, so a
  prof_cpu_ test selected under another profile fails instead of
  passing with no profile.
- scripts/samply-wrapper.sh: nextest runs it as <wrapper> <test binary>
  <arguments>. It runs `samply record --save-only --no-open
  --unstable-presymbolicate` and writes target/profiling/<test>.json.gz,
  with a symbols sidecar so `samply load` opens it without the build.
  samply 0.13.1 exits with the test's status, but with 0 when the test
  is killed by a signal (measured): under a plain wrapper an aborting
  test PASSED. So a 0 counts only with libtest's pass line for one test.
- .config/nextest.toml: `experimental = ["wrapper-scripts"]`,
  [scripts.wrapper.samply] (relative to the workspace root), and
  [[profile.prof.scripts]] for `test(/^prof_cpu_/)`. If the feature is
  renamed or dropped, nextest refuses the config (exit 96 for an
  unknown feature, 95 for a wrapper script without it; measured on
  0.9.140), so no test runs unprofiled.
- .github/scripts/tests/test-samply-wrapper.sh, run by ci-scripts: the
  wrapper against a fake samply that behaves as measured and a fake test
  binary, over every ending (pass, fail, no test, killed), samply
  installed or not, a profile written or not, and three test names
  (149 checks). Eight broken copies of the wrapper each fail it.
- plan-ci.py: a change to the wrapper runs ci-scripts, not everything.

Controls, against the real samply: a failing prof_cpu_ test fails (exit
100); an aborting one fails through the guard, and passes with the
guard removed; the test refuses without the wrapper; the profile's
symbols name thrust_api_v1, thrust_core, thrust_adapters_memory and
thrust_profiling, and an unrelated binary's name none of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: the CPU profile, and the test-suites plan's status

AGENTS.md's commands table gains the profiles' command. The crate's
description and module doc, crates/testing/README.md and
docs/src/testing/techniques/performance.md describe the CPU profile and
the wrapper. The plan: PR 4 merged in #267, PR 5 in review, and what PR
5 found (samply's exit status on a signal, the refusal without the
wrapper, how nextest reacts if the experimental feature changes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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