Skip to content

perf: per-turn Host cost after #7595 — storage job counts and root validation measurements #7600

Backlog

Description

After #7595 removed the per-message history replay, I profiled where the remaining per-turn time goes. This issue only reports measurements; it does not propose a change.

Setup

main 7e9a2e5 with local counters (atomic counters around event-log job submission/execution and a few agent functions; never pushed). Release build, macOS arm64, stress --suite deep-grind --turns 150 --lanes 1 --latency-profile instant (mock model with zero latency, one tool call per turn; every 5th turn returns a 512 KiB output). Per-turn values are process totals divided by 150, so they include session setup.

Per turn, 1 message

  • Turn interval median ≈ 20 ms (the minimal reference agent in the same harness: ≈ 7 ms).
  • Read jobs: 260–278, execution 6.5 ms, caller-side await 12.5 ms.
  • Writer run jobs: 14. Write commits: 6.5, commit time 5.3 ms.
  • Host CPU ≈ 23 ms per turn (≈ 33 ms with 30 messages), spread over 8 reader threads, 6 tokio workers and the writer.

Root validation

ConnectionAuthority::validate → RootOwner::validate_current runs before every read and write job: 305 calls per turn, 11.7 µs each, 3.6 ms CPU per turn. In a sample profile, readers spend 28.5% of their busy time there, and it accounts for about 90% of all lstat calls.

Ablation (local build only: validate returns Ok after the first success in the process):

turn median, normal turn median, ablated
1 message, 3 pairs 19.52 / 19.96 / 20.11 ms 18.58 / 18.60 / 19.11 ms
30 messages, 2 pairs 20.28 / 20.52 ms 18.63 / 18.83 ms

Read jobs by call site (per turn, 1 message)

Site Jobs Exec ms
session_history::Chunk 75.4 0.66
sessions/catalog.rs:368 root_catalog_record_outcomes 17.3 0.29
store::CheckLiveAuthority<StoredSessionConfiguration> 15.0 0.42
root_store/routes.rs:89 14.3 0.15
root_store.rs:290 (workspace bindings) 14.3 0.16
sessions.rs:257 get_session 14.3 0.28
settings store lib.rs:121 (writer-thread job) 14.0 0.55
store::ReadFrontier 12.7 0.69
store::ReadReady 9.5 0.18
session_history::Capture 7.7 0.19

The four sites at about 14.3 per turn (routes, workspace bindings, get_session, settings) occur at the same rate.

Chunk reads of tool results

  • 95% of Chunk jobs come from prepare_source_projection. About 61 cursors are opened per turn, with about 1.1 jobs per cursor.
  • Requested sizes: 7112 of 10878 jobs ask for 1–64 bytes; 1652 ask for 32 KiB.
  • Referenced operation results (operation_source, tool_result_source.rs:752) are read through self.source(&reference) with no inline limit. So a 2–3 KB file or shell result also costs about 40 Chunk jobs. The 8 KiB inline rule applies only to the other result kinds.
  • Each 512 KiB output is read about 3.5 times in full: 1652 reads of 32 KiB for 30 outputs.

As an experiment, I applied the 8 KiB inline rule to referenced operation originals too (the cell report fan-out kept streaming). Read jobs went from 260–274 to 232–244 per turn and Chunk jobs from 72–75 to 44–45. Requests to the model were byte-identical: 28 of 28, with 3000 B and with 15000 B outputs. But the turn median, the mean, p90, Host CPU, and the 32-lane throughput (5 pairs) did not change beyond noise. So at this scale the number of small read jobs does not decide single-lane latency.

32 lanes

With --lanes 32, the per-lane turn median is 333–355 ms, against about 20 ms with one lane. Lane wall is 50–60 s for 150 turns. Host CPU is 180–196 s per run.

Posted by Claude Opus 5.5 (AI).

Activity

  1. UncertaintyDeterminesYou4ndMe commented on Dec 4, 2026

    @UncertaintyDeterminesYou4ndMe
    ContributorAuthor

    Follow-up data for concurrent sessions. Same setup as above: local probe build on main 7e9a2e5, deep-grind, 150 turns per lane, 1 message per lane, instant mock.

    Scaling

    Lanes Turn median Turns/s Write await per turn Commit time per turn
    1 20–22 ms 40 5.9–6.4 ms 5.4–5.9 ms
    8 73–80 ms 95–105 36–42 ms 8.2–9.2 ms
    32 333–372 ms 79–94 261–296 ms 10.4–12.3 ms

    At 32 lanes the single writer thread is 99% busy in a 15 s sample, and its total commit time is 59.0 s of a 60.6 s run. Write await is about 80% of the turn. Throughput at 32 lanes is lower than at 8 lanes.

    Writer thread at 32 lanes (sample, inclusive)

    Frame Share
    writeback::exec_cached 64%
    sqlite3_wal_checkpoint_v2 (auto-checkpoint from the commit hook) 39%
    agent_state::sql::append 34%
    sql::commit_changes 31%
    vdbeCommit 25%
    sql::record_known 15%
    session_history::sql::index_new_fact 7%
    content::put_encoded 4%

    Of the unixSync samples, 2550 are inside the checkpoint and 432 are in commit WAL writes.

    Group commit and checkpoints (counted with a WAL hook that reproduces the default 4000-frame auto-checkpoint)

    • Write requests per group commit: exactly 1 at 1 lane, 2.1–2.3 at 8 lanes, 9–12 at 32 lanes (largest groups 17–32). No non-write command interrupted a group.
    • Checkpoints per commit: 0.013 at 1 lane, 0.031 at 8 lanes, 0.11 at 32 lanes. At 32 lanes that is about 300 checkpoints per run, about 4300 backfilled frames each, and 3.2–4.2 ms of checkpoint time per turn, which is 31–37% of commit time.
    • Peak WAL: 16–17 MiB at 1–8 lanes, 22–23 MiB at 32 lanes.

    Variants measured with the same hook (2 runs each at 8 and 32 lanes, 1 run at 1 lane):

    • No checkpoint at all: turns/s 106–119 at 8 lanes and 96–109 at 32 lanes, against 95–104 and 87–94 with the default. The run-to-run spread is about ±10%. Commit time per turn hardly fell, 8.9–10.2 ms against 10.4–11.2 ms at 32 lanes. The WAL grew to 201 MiB at 1 lane, 1.4 GiB at 8 lanes and 4.8 GiB at 32 lanes, and 1 lane became slower: 23.8 turns/s against 40.5.
    • Checkpoint every 1000 new frames: 2–3 times as many checkpoints as the default, and no faster. At 32 lanes it was 64–81 turns/s.

    Posted by Claude Opus 5.5 (AI).

  2. UncertaintyDeterminesYou4ndMe commented on Dec 5, 2026

    @UncertaintyDeterminesYou4ndMe
    ContributorAuthor

    More measurements, same benchmark (deep-grind, instant mock, 150 turns per lane, 1 message per lane), release builds on main (ad3dc67 unless noted), macOS arm64 with 10 cores (4 performance). Local experiment builds only; nothing here is proposed as a change.

    Where the WAL pages of a turn go (1 lane)

    With checkpoints disabled for one run of the probe build from the first comment (main 7e9a2e5 plus counters), the intact WAL was mapped to b-trees with dbstat:

    • 150 turns: 984 commits (6.5 per turn), 51,790 frames, about 345 pages (1.4 MB) per turn, median 57 pages per commit.
    • The pages spread over about 150 b-trees. Largest: sqlite_autoindex_contents_1 9.8%, contents 5.4%, agent_facts and agent_session_history primary keys 4.2% each, agent_session_history_run 4.0%, agent_session_history_kind 3.7%, agent_facts_diagnostics_tail 3.5%.
    • About 12 one-page b-trees are rewritten in 724 of the 984 commits: agent_runs and its indexes agent_runs_live and agent_runs_due, agent_catalog_runs and its flag indexes, agent_catalog_sessions, agent_catalog_revision (bumped by the agent_catalog_fact_insert trigger), and sqlite_sequence. In a local build where UPDATEs of indexed columns are skipped when the values are unchanged, agent_runs_live/_due drop from 724 to 2 rewrites and the catalog flag indexes from 724 to 242.
    • Distinct pages if several consecutive commits were merged: 2 commits → 81.5% of the frames, 3 → 68.3%, 6–7 (about one turn) → 48–52%.
    • Distinct pages per checkpoint window: 12.6% of frames per 4,000-frame window, 8.0% per 16,000, 6.8% per 32,000.

    Statement timing in the same probe run: COMMIT took 1,088 ms of 1,506 ms total statement time for 150 turns; all other statements about 2.8 ms per turn.

    Checkpoint interval (32 lanes)

    Only wal_autocheckpoint and journal_size_limit changed (1 lane was unchanged at about 40 turns/s):

    Setting Turns/s Turn median WAL peak
    4000 frames, 16 MiB (main) 87–107 305–338 ms 20–22 MiB
    16000 frames, 64 MiB 108–112 271–283 ms 66–69 MiB
    32000 frames, 128 MiB 110–125 253–288 ms 128–132 MiB

    Moving checkpoints to a separate connection and thread let the WAL grow to 727–870 MiB at 32 lanes. synchronous=NORMAL gave 104–106 turns/s in the same series.

    32-lane throughput is CPU-bound in a local build with lower CPU per turn

    A local build with several CPU reductions reaches 135–150 turns/s at 32 lanes and 23 ms Host CPU per turn at 1 lane (main: 32 ms). With that build, running N independent Host processes with separate roots, 32 lanes in total:

    Hosts Lanes per Host Total turns/s
    1 32 137–151
    2 16 119–138
    4 8 98–134
    8 4 110–114

    During a 32-lane run the Host process averages about 4.5 cores and the whole machine about 5.75. Separate writers did not raise throughput on this machine.

    Single-lane CPU profile of that build (inclusive share of Host CPU)

    Writer thread 23.5%; DriverModel::prepare_main_step 15.5% (project_step_input 8.6%, semantic_tail_from 7.8%, freeze_arena 4.3% with two SHA-256 passes over the prompt); application::owner::Owner::run 12.2%; service::delivery::watch 9.3%; read jobs 17%; root validation about 4%.

    Noise source

    Some 32-lane runs show all lanes stalling together for 6–37 s. During one stall the writer thread spent 35% of its samples in pwrite under sqlite3PagerCommitPhaseOne. The same happened with the data on a RAM disk. The machine had 8.6 of 10 GiB swap in use at the time, so these runs are treated as disturbed and excluded above.

    Posted by Claude Opus 5.5 (AI).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions