8.2 KiB
Read-only queue performance review — 2026-10-19
Conclusion
There are concrete redundant filesystem operations that can be removed while retaining durable writes and identity checks. The strongest simple candidate is deduplicating project access preparation before resolving paths. Logging also repeats metadata/directory work. The current profile does not prove these changes alone will bring the independent 40.90-second result below 30 seconds. A measured result is required; the threshold should remain unchanged.
No source edits, tests, CAD, application operations, or Git mutations were performed. This report is the only output written.
Evidence and interpretation
build/release-queue-profile-20261019-v2/stress-metrics.json records 1,000 steps, 91 saved steps, 36.731 seconds, and approximately 2.34 MB peak memory. The separate independent 40.90-second failure was supplied by the coordinator. The profiled test retains tracemalloc, so Python/path allocation reductions can matter as well as disk calls.
Selected cumulative profile costs:
| Path | Calls | Cumulative seconds | Interpretation |
|---|---|---|---|
execute_step |
1,000 | 20.756 | Broad parent; includes child work below |
_write_current_command |
1,000 | 8.341 | Predominantly required durable command publication |
append_task_event |
approximately 1,043 | 8.301 | Required event evidence plus repeated metadata work |
_io.open |
approximately 7,131 | 7.129 | Global cost; includes required files and test worker |
nt.stat |
approximately 14,663 | 4.375 | Global cost; some redundant calls, many identity checks |
nt.fsync |
approximately 2,063 | 3.939 | Required durability; retain |
_prepare_project_access |
1 | 2.654 | Repeats project resolution across command rows |
nt.replace |
approximately 1,020 | 2.005 | Atomic publication; retain |
These costs overlap and must not be added. In particular, BatchBackupCoordinator.__exit__/shutdown/join appears as about 33 seconds, overlapping the queue/worker-thread work in this profile. It is not evidence of an additional exclusive 33-second cleanup operation. The test stubs the actual backup copy; removing shutdown(wait=True) would weaken cleanup rather than establish a performance fix.
Ranked optimization candidates
1. Deduplicate project paths before expensive access preparation
Location: legacy_paths.py:107, _prepare_project_access.
The helper reads all command rows and executes Path(value).resolve(strict=False) before testing whether that project's access pair was already produced. This test has 1,000 commands but only 20 project paths. For ordinary short paths, no access row is produced at all, so the existing pair not in rows guard never helps.
Use an invocation-local set of raw project-path field values and process each distinct value once before resolution, file queries, short-path lookup, or alias creation. Keep the access pair output unique and retain strict alias-to-project identity validation. Do not cache across invocations or remove validate_project_access before/after workers.
Expected effect: expensive project preparation falls from 1,000 to 20 evaluations in this workload. The profile assigns 2.654 seconds to the entire helper, which bounds the available saving; it cannot recover the whole regression alone.
Verification: repeated command rows should produce the identical access manifest, with resolution/short-path calls scaling with distinct project strings. Existing long-path/redirected-entry tests must still pass. Per-worker identity checks must still reject an alias changed after preparation.
2. Replace existing-log exists() plus stat() with one fresh metadata read
Location: retention.py:29, rotate_text_log.
For each normal existing log, path.exists() performs a stat, immediately followed by path.stat().st_size. One fresh stat can answer both existence and size. Preserve the missing-file behavior and error handling deliberately, and retain all link checks and backup rename checks when rotation is needed.
This removes one filesystem metadata call per rotation check without changing log bytes, event count, flush/fsync, sequence calculation, rotation threshold, or atomic operations. It also benefits callers beyond the event log.
Verification: missing log, existing below-threshold log, rotation, linked logs/backups, and filesystem error behavior. Instrument metadata calls for the below-threshold existing-file case; it should use one query rather than two. Do not replace live checks with a permanently cached file size.
3. Avoid failed mkdir calls for already-existing log directories
Locations: logging_setup.py:225 (_task_directory) and quick_run.py:1082 (_append_log).
Both call mkdir(parents=True, exist_ok=True) on every append. On an existing Windows directory, pathlib attempts mkdir, catches the existing-directory error, and checks whether the path is a directory. A fresh is_dir() fast path can avoid that failed mkdir call; create the directory with the existing code only when the check is false. Keep task-ID validation on every call.
This retains a live directory check and recovery after directory deletion rather than trusting an unvalidated lifetime cache. It is a small optimization with uncertain timing benefit, not a guaranteed multi-second saving.
Verification: existing directory, removed directory recreated on next append, non-directory collision, invalid task IDs, permission failures, and concurrent first append. Event contents, sequences, immediate readability, and fsync count must remain unchanged.
4. Cache pure command/session path construction, not filesystem trust
execute_step repeatedly constructs the same batch.request, current-command.tsv, current-state.tsv, and related parent paths. A session can retain immutable Path/string values established at startup while still performing every live file stamp, per-step command write, request write, and post-worker identity comparison.
The high pathlib allocation counts make this a plausible secondary saving under tracemalloc, but the profile does not isolate its exclusive cost. Prefer the first three candidates before adding session fields. Never cache a stamp as proof that a file remains unchanged.
Work that should remain
- The pre-append event path stamp, post-fsync handle stat, and final path stamp serve different purposes. The final path-vs-handle comparison explicitly accounts for Windows ctime semantics and binds the sequence cache to the file actually written. Do not remove it as an apparent duplicate. External append/replacement and rotation must continue invalidating the cache (
test_event_append_cache.py). current-command.tsvcontains a different confirmed job on each step. Its fsync plus atomic replace and the post-worker stamp comparison are not redundant with the full queue or status file. Preserve deletion/change detection.batch.requestbinds the worker's batch mode to the expected job ID; VBS reads and compares it. The write is not shown to be useless merely because the command line also contains a job ID. Skipping it would be a protocol change requiring separate evidence, not the safe first optimization.- Keep every
quick_run_executedevent and its timing/state/identity fields, event fsync, uncertain markers, backup state publication, atomic queue commit, and executor cleanup boundary. - Do not disable tracemalloc, reduce the simulated queue, skip saved steps, falsify statuses, move required work outside the measured operation, or loosen the 30-second gate.
Suggested validation sequence
Implement one candidate at a time only after the active real acceptance run is finished. First verify semantic guards and call-count reduction, then rerun the unchanged independent 1,000-item test in the same environment. Once correctness checks pass, measure the isolated performance gate and retain the raw metrics. Use a new profile only if the gate still fails or the result leaves the bottleneck uncertain; use per-thread wall spans/counters for backup overlap rather than subtracting the 33-second shutdown attribution.
There is a defensible low-risk optimization direction, but no evidence-backed complete solution to the 10.90-second deficit yet.