Skip to content

Served state labels each revision by scanning the whole log, so it grows with revisions × events #5886

Closed

Description

@leaf-agent

On a page with many revisions, the served state and leaf page state grow with revisions × log events. That breaks the ceiling in root AGENTS.md, Responsiveness, that computing a reading grows no faster than the page times the logarithm of its size. The cause is revision_label and stamped_version. Each scans the whole log, and the reading calls them once per revision: files.py:296 labels every version descriptor, and served_state/page.py:74 labels every revision in the served state. One pass over the notes could label every revision.

What the bench reads. Server revisions table, state ms by page size, from the daily scheduled ci run's bench-report:

run head events at 1600 128 256 512 1024 1600 exponent
42473165114 (11-08) f926f4fa7 1 3.4 3.5 3.8 4.5 5.5 –
42604289041 (11-09) 28c3b37f3 1600 4.4 6.9 14.7 50.0 113.5 1.81
42802603869 (11-10) e6756ad43 1600 5.9 10.2 24.6 89.4 209.1 1.88
43007021682 (11-11) a52abb1bb 1600 5.2 8.6 20.8 74.2 200.1 1.97

agent ms (leaf page state) follows the same curve: 210 ms at 1600 on 11-11. The runs from 11-06 to 11-08 all read about 6 ms at 1600.

Why it shows now. #5716 (4363db4) gave each activated revision an activation event. The revisions collection activates n versions, so its log went from 1 event to n, and the per-revision scans became visible. Locally, leaf-dev bench revisions --read server --sizes 256,1024,1600 reads 4.1, 5.6 and 6.5 ms on 4363db4's parent and 10.3, 109.3 and 274.7 ms on 4363db4. Real pages already paid this cost whenever they had many revisions and a long log. #5716 only made the bench page carry one. On current main (b3387f111), --profile attributes the growth to revision_label (exponent 1.74) and stamped_version with its generator (1.69–1.88).

Reproduction
uv run leaf-dev bench revisions --read server --sizes 256,1600 --rounds 1 --profile

On b3387f111 in a 4-core CI runner:

revisions state: superlinear functions
         0 ->      245 ms  exponent  1.74  revision_label (files.py:303)
         0 ->      123 ms  exponent  1.66  stamped_version (files.py:233)
         0 ->      121 ms  exponent  1.86  <genexpr> (files.py:236)

The commits between the last low reading and the first high one (f926f4fa7..28c3b37f3) that touch src/leaf are #5715, #5714, #5717, #5716, #5720 and #5440. The parent/child comparison above isolates #5716.

Activity

  1. leaf-agent commented on Nov 12, 2026

    @leaf-agent
    CollaboratorAuthor

    #5889 has the fix. files.revision_labels sorts the log's stamps once and labels every revision by bisecting them, replacing the scan per revision. On this runner, state ms at 1600 revisions in leaf-dev bench revisions --read server drops from 161.8 to 26.0, and --profile no longer reports a superlinear function for state or agent. The labels are unchanged, and a new model test covers them. Its CI and landing go through tend-land.

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