Repository navigation
Description
Problem
The second review of PR #6583 (#4668) found two costs on main (b2a277b) in src/devops_cli/roadmap/stores/listing_shared.py. The review measured them on the real devops-cli snapshot (6,571 records, 36.3 MB of JSON, 13.9 MB with zlib):
ValkeySnapshotStore.write(line 293) encodes the JSON of all records, computes their blake2b digests and compresses all of them. Only after that does it decide OLDER, UNCHANGED or a delta (_holds, line 313). A save with no change takes 0.73 to 0.89 s in an idle process, and zlib is most of that time. The old local save took 0.16 s.IncrementalListing.readsaves after each listing read, and the Service runs one thread for each repository and lane. With one other busy Python thread, the same save took 17 s in one measure. The verifiers found that number too large, but the CPU cost on the UNCHANGED path holds.- Lanes that load one repository at the same time do not share one scan.
records(line 228) holds no lock for the repository. So each lane does the full HSCAN, inflate and validate, and builds its own copy (about 60 MB each; tracemalloc peak 97.7 MB for one load). The load budget covers only the HSCAN loop, not inflate and validate. After a restart, up to 13 of the 14 lanes of devops-cli load in their first round.
Expected
- The cost of a save follows the number of changed records. The store compares the records with
_seenfirst, then decides OLDER, UNCHANGED or a delta, and encodes, hashes and compresses only the records that the write sends (all records only for_replace). - One scan for each repository in a process: a lock for each repository during the scan, and a lane that waited reads
_seenagain before it scans. The load budget also covers inflate and validate.
Acceptance criteria
- Test first: a save with no changed record compresses no record (count the calls of the compressor). The test fails on the base.
- A test: a save with one changed record compresses one record.
- A test: two threads load one repository at the same time, and the Valkey fake records one HSCAN.
- A test: a load whose inflate goes past the budget stops and counts the budget stop.
- A command proves the time: the save of the unchanged devops-cli snapshot takes less than 0.2 s, measured before and after the change.
Dependencies
- fix(roadmap): correct visibility, keys and bounds of Valkey caches #6611 changes the same file: no merge order, rebase before the second.
Source
Source: #6583
Alternatives check of 2026-11-21: not-applicable.
Class: perf, no search.
Tool: none found.
Proposed design
Problem statement
The shared Valkey snapshot store encodes, hashes and compresses every record on each save. An unchanged save costs 0.73 to 0.89 s, and zlib is most of that time. Lanes that load one repository at the same time each run a full HSCAN, inflate and validate, and build a copy of about 60 MB. The change makes the save cost follow the changed records. It makes one scan for each repository in a process. The load budget covers inflate and validate.
Acceptance criteria
Requirement: Unchanged save compresses no record
A save whose records equal the stored copy and whose watermark and full read are not newer SHALL return BrainWrite.UNCHANGED before it compresses any record.
Scenario: Second save with no change
- WHEN A test saves one listing to a fake Valkey tier. It resets the
zlib.compresscall count. It saves the same listing again with no changed record. It counts the calls ofzlib.compress. - THEN The second save returns
BrainWrite.UNCHANGEDand the compressor call count is 0.
Requirement: Older write compresses no record
A write whose watermark is older than the stored watermark SHALL return BrainWrite.OLDER before it compresses any record.
Scenario: Older watermark
- WHEN A test stores a snapshot with a newer watermark. It resets the
zlib.compresscall count. It writes a snapshot with an older watermark. It counts the calls ofzlib.compress. - THEN The write returns
BrainWrite.OLDERand the compressor call count is 0.
Requirement: One changed record compresses one record
A save that changes one record SHALL compress only that record and SHALL send a delta with the changed record and the new meta.
Scenario: One-record delta
- WHEN A test primes the store with a listing. It changes one issue. It resets the
zlib.compresscall count. It saves the listing again. It counts the calls ofzlib.compressand the fields of the recordHSET. - THEN The compressor call count is 1 and the record
HSETof the delta carries only the changed issue number and its compressed value.
Requirement: Concurrent loads share one scan
Two lanes that load one repository at the same time MUST perform one scan of its shared snapshot.
Scenario: Two threads load one repository
- WHEN A test starts two threads at the same time. The threads call
ValkeySnapshotStore.recordsfor one repository with no_seenentry. The fake snapshot has fewer fields thanDEFAULT_BRAIN_SNAPSHOT_SCAN_COUNT. - THEN The fake tier records one
hscancall and both loads return the same records.
Requirement: Load budget stops inflate and validation
A load MUST stop and count a budget stop when inflate or validation passes DEFAULT_BRAIN_SNAPSHOT_LOAD_BUDGET_SECONDS.
Scenario: Inflate passes the budget
- WHEN A test uses a fake
clock.monotonicthat passes the load budget during inflate of a record. - THEN The load returns
NoneandVALKEY_CACHE_ERRORS_TOTALshows one increment witherror=budget.
Requirement: Unchanged save stays under 0.2 s
The unchanged save of the devops-cli snapshot SHALL take less than 0.2 s.
Scenario: Unchanged devops-cli snapshot benchmark
- WHEN A benchmark test loads the 6,571-record devops-cli snapshot into a fake tier. It primes the store. It saves the snapshot again with no changed record.
- THEN The benchmark reports a median save time of less than 0.2 s.
Existing Tool Considered
The alternatives check of 2026-11-21 in the issue body gives not-applicable: class perf, no search, and Tool: none found. The change builds its own code and reuses the standard-library modules zlib and hashlib already in src/devops_cli/roadmap/stores/listing_shared.py. Written cost: about 40 changed lines, an estimated 6,000 tokens and 2 hours to build, keep and fix until the tests pass.
Key questions
- How does the write avoid compressing records that it does not send?: Compare the incoming records with the
_Seenentry of the repository before JSON encoding. When_seen.issuesis not None and_seen.digestequalsheld.meta.digest, compare eachIssueRecordby number and equality. Decide OLDER from the watermark and schema. Decide UNCHANGED from the equal records and the storedfull_atandwatermark. Decide a delta from the changed, new and removed numbers. Encode, digest and compress only the changed and new records. Reuse_seen.digestsfor the unchanged records. Buildmetafrom the merged digests._replacestill encodes, digests and compresses all records._updatetakes the full merged digest map to compute removed numbers. (best practice) [sources: src/devops_cli/roadmap/stores/listing_shared.py, src/devops_cli/config/defaults.py:750]- Chosen: Compare with
_seenbefore encoding. The store already keeps the records and digests for the repository, so the unchanged and delta paths skip zlib and JSON encoding for unchanged records. - Rejected: Encode and hash all records, then compare digests. This is the current cost, and zlib compression dominates the unchanged save.
- Rejected: Compare only the stored
meta.digest. The digest cannot be known without encoding every record, so it does not avoid the cost.
- Chosen: Compare with
- How does the store make one scan for each repository when lanes load at the same time?: Add a lock for each repository around the scan. After a lane gets the lock, read
_seenagain. Return its records when their digest is the held digest. Otherwise scan once and store the result. A lane that already has_seencan return before it takes the lock. (best practice) [sources: src/devops_cli/roadmap/stores/listing_shared.py]- Chosen: A lock for each repository with a second
_seenread. Lanes of different repositories do not wait, and a waiting lane reuses the first scan. - Rejected: One global lock. It serializes loads of every repository.
- Rejected: No lock. This is the current duplicate scan cost.
- Chosen: A lock for each repository with a second
- Which parts of a load does the time budget cover?: The budget covers the HSCAN loop, zlib inflate of each record and validation of each record. A step that passes the budget returns
None. It counts one budget stop witherror=budgetand the step inop. (best practice) [sources: src/devops_cli/roadmap/stores/listing_shared.py, src/devops_cli/config/defaults.py:750]- Chosen: HSCAN, inflate and validate. The issue states that the load budget covers only the HSCAN loop today and must cover inflate and validate.
- Rejected: HSCAN only. This is the current gap.
- Rejected: A hard limit on each record. A per-record limit does not bound the total load time.
- How does the test count compressor calls?: Patch
zlib.compresswith a wrapper that increments a counter and calls the real function. Reset the counter after the priming save. Use it for the unchanged, older and one-record delta saves. (best practice) [sources: src/devops_cli/roadmap/stores/listing_shared.py, tests/roadmap/stores/test_listing_shared.py]- Chosen: Patch
zlib.compress. It counts calls without a change to the production API. - Rejected: Measure elapsed time. Time is noisy and does not prove that no record was compressed.
- Rejected: Inspect the Valkey fields. An unchanged save writes no record field, so it cannot show whether compression ran.
- Chosen: Patch
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 21, 2026
The save path wastes 0.73 to 17 s of CPU and each lane duplicates a 60 MB scan, which is a clear performance degradation.Both items work on listing_shared.py; #6611 fixes visibility, keys, and bounds, while this candidate restructures the save and scan paths for performance.devops-cli-service commentedon Nov 21, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Nov 21, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
14 remaining items
test(roadmap): two lanes that load one repository send one HSCAN (#6614)
perf(roadmap): scan a repository once for the loads of one process (#…
test(roadmap): the load budget covers the wait and the inflate (#6614)
perf(roadmap): bound the wait, inflate and validation of a load (#6614)
docs(roadmap): name the shared scan and the save cost of the snapshot (…
test(roadmap): a field of another number, a save during a scan, the v…
fix(roadmap): keep a newer known copy and refuse a record under anoth…
docs(openspec): archive the save and the scan of the shared snapshot (#…
devops-cli-service commentedon Nov 21, 2026
Released in v0.188.3: https://github.com/dan-petty/devops-cli/releases/tag/v0.188.3
devops-cli-service commentedon Nov 21, 2026
Live since 2026-11-21 19:08 UTC