Skip to content

perf(file-system): Fix quadratic file rescans in the FS request queue#2011

Draft
vdusek wants to merge 1 commit into
masterfrom
worktree-fix-fs-rq
Draft

perf(file-system): Fix quadratic file rescans in the FS request queue#2011
vdusek wants to merge 1 commit into
masterfrom
worktree-fix-fs-rq

Conversation

@vdusek

@vdusek vdusek commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

The file system request queue client was O(n²):

  • Every cache refresh globbed and parsed every request file ever written (handled files are never deleted from disk).
  • forefront=True invalidated the whole cache, and RequestManagerTandem adds every loader request with forefront=True, which triggered a full rescan per processed request.
  • The blocking json.load ran on the event loop.

Processing a 10k RequestList through the tandem meant roughly 50M file parses.

Changes

  • _refresh_cache now derives pending requests from the recoverable state's key→sequence maps and reads only those files, instead of globbing and parsing the whole directory.
  • New forefront requests go straight to the front of the in-memory cache. The cache is invalidated only when an existing request is repositioned, or when it's at capacity.
  • Handled requests are pruned from the pending state maps (they stay in handled_requests for deduplication), so cache refreshes, is_empty, and the persisted state blob scale with the backlog rather than with every request ever processed.
  • _parse_request_file reads the file in a single asyncio.to_thread call instead of running json.load on the event loop.

Results

Processing 200 requests through the tandem pattern went from 20,100 file parses (2.8 s) to 1 (0.3 s), and scaling is now linear (2,000 requests in about 2.6 s). Ordering semantics (forefront LIFO, regular FIFO), deduplication, and crash-recovery behavior are preserved and covered by new regression tests.

Logging changes

The file system request queue no longer emits the Request <unique_key> not found in state, skipping. warning. The cache refresh no longer scans the queue directory, so orphaned request files (e.g. written by another process) are silently ignored.

BREAKING CHANGE: The file system request queue no longer emits the 'Request <unique_key> not found in state, skipping.' warning. The cache refresh no longer scans the queue directory, so orphaned request files (e.g. written by another process) are silently ignored.
@vdusek vdusek added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Jul 2, 2026
@vdusek vdusek self-assigned this Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.44%. Comparing base (7780e78) to head (be52914).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...rage_clients/_file_system/_request_queue_client.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2011      +/-   ##
==========================================
+ Coverage   93.35%   93.44%   +0.09%     
==========================================
  Files         179      179              
  Lines       12482    12467      -15     
==========================================
- Hits        11652    11650       -2     
+ Misses        830      817      -13     
Flag Coverage Δ
unit 93.44% <95.83%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek changed the title perf!: Fix quadratic file rescans in the file system request queue perf(file-system): Fix quadratic file rescans in the FS request queue Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants