Skip to content

startup: answer draw and Dispatch cache probes from the cache index - #3570

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
JohnConnorNPC:startup/cache-index-probes-v2
Nov 30, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
JohnConnorNPC:startup/cache-index-probes-v2

Conversation

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Summary

Under Wine, looking up a name that is missing from a shader cache directory with ~274k entries costs ~155 ms, because
the case-insensitive lookup reads the whole directory. The draw and Dispatch paths make such lookups with draw_lock
held: request parts, the slot 57 base manifest, the graphics and compute manifests, and the compute <key>.cs.hlsl.
Compute manifest retries also re-read every stale <key>.txt on the retry schedule.

This PR extends src/startup_stubs/cache_index.h (#3433, #3436). Those probes now ask the index first and skip the
disk for an absent name. An unchanged compute manifest miss is repeated without I/O.

  • Change feed. One thread queues ReadDirectoryChangesW on the cache (top level: names, last writes, sizes) and then
    makes the listing, so every file created after the listing began is in a change record. Created and renamed-to
    names are added to the index. The listing moves off the caller: these probes never make or wait for it.
  • req_ names (written only by runtimes): absent from the listing and from this process's own writes means skip the
    disk. A write that finds such a name present is counted as a contradiction.
  • Translator files (<key>.txt, <key>.cs.hlsl): answered absent only while the feed is reading, and only if it was
    reading before the listing began. A dropped batch or any feed error sends them back to the disk.
  • Compute manifest retries (second commit): a retry takes a change mark before it looks on disk. While no <key>.*
    name has a change record from that mark on, the next retry repeats the miss without I/O. A created, removed,
    renamed or rewritten file of that key, or a feed that is not reading, sends the retry back to the disk.
  • x2w-draw cache probes (skipped as absent/on disk): ... every 10 s: per probe, the feed state, records, added names,
    lookups that found a name added after the listing, and contradictions.

On its own, this did not change where the measured runs stop (below). It removes the file-system cost from
draw_lock; the in-process compute translation remains the main holder of the lock (#PR-2).

Tests

Wine only (Proton wine 11.0, clang-cl cross build, main52 init cache). Windows CI has not run.

startup_cache_index_check and controls, judged by their CTest PASS/FAIL regular expressions:

test result
startup_cache_index exit 0, 0 failed
..._per_call_control fails (a) only (515 disk probes)
..._no_added_control fails (j) only: a created file never reads present
..._no_rename_control fails (j) only: a renamed-to file never reads present
..._listing_only_control fails (k), (l), (m) only: absent instead of unknown without a usable feed
..._ignore_changes_control fails (q) only: a manifest published after the miss is never picked up
..._names_only_control fails (o) only: a file rewritten in place never reads changed

Under Wine: (j) another process's create and rename are seen; (m) a 16-byte batch buffer drops with error 1022;
(q) 50 retries of an absent manifest make 1 look on disk, and a manifest published later is picked up with one more.
docs_links_check and bidi_controls_check: exit 0.

Measured (local game runs, one console executable under test; same inputs and recipe for every run)

The runs are on main 26df182 with these commits cherry-picked (same patch-ids), so that the native shader revision
matches the baseline's warm cache. A local diagnostic timed the draw_lock-held translation blocks.

run tree presents stop (last heartbeat) run ends (same access violation)
A1, A2 26df182 181.2 s, 181.1 s 216.2 s, 217.0 s
C1, C2 + first commit 166.4 s, 191.3 s 202.1 s, 231.2 s
  • C skipped 190 of 206 and 235 of 255 .cs.hlsl probes; every other probe was a hit on disk. No file was created in
    the cache during these runs, so the feed read 0 records.
  • With the probes gone, Dispatch's in-process translation still held draw_lock for 9.5 s of each 10 s after the
    stop (manifest load: at most 0.6 s per 10 s).
  • With PR-2 (worker translation), the same executable ran for 1881 s. The index skipped 22047 .cs.hlsl probes;
    without it, those would be ~57 min of draw_lock-held misses (inference: count x 155 ms). That run ended when
    ~700 stale compute manifests were re-read on every retry: the manifest load held draw_lock for 4.8-8.8 s per 10 s,
    with no changes in the cache (feed: 10 records in the run). The second commit targets exactly those re-reads.
  • With both commits and PR-2 (3 workers), the run lasted 2729.5 s, against 1881.7 s and 2113.3 s with one worker and no
    retry cache. All 38,999 manifest retries were repeated without I/O, none went to disk (feed: 48 records,
    0 contradictions). The manifest load's longest call was 403 ms; at the end of the run it took 0-0.1 ms per 10 s. That
    run ended when the host ran out of memory (swap full, memory pressure 57% over 5 min; measured right after the run),
    not on a stand-in stall.

Hypothesis, not measured: on Windows a miss is cheap, so the gain there is small; the change targets Wine.

Under Wine a missing name in the ~274k-entry shader cache costs ~155 ms,
and the draw and Dispatch paths probed the cache root with draw_lock held:
request parts, the slot 57 base manifest, graphics and compute manifests
and the compute .cs.hlsl. These now ask the cache index first and skip
the disk for an absent name.

The index gains a change feed: one thread queues ReadDirectoryChangesW on
the cache, then makes the listing, and adds every created or renamed-to
name. req_ names (written only by runtimes) use the listing and this
process's own writes. Translator files are answered absent only while the
feed is reading and was reading before the listing began; a dropped batch
or a feed error sends them back to the disk. These probes never make or
wait for the listing, so draw_lock no longer waits for it.

A 10 s counter line reports each probe's skipped and on-disk counts, the
feed state, records, added names, lookups that found a name added after
the listing, and contradictions.
A compute manifest that is absent, stale or unmarked is looked for again
on the retry schedule, and each retry re-reads <key>.txt with draw_lock
held. With hundreds of such keys those re-reads add up to seconds of
draw_lock per 10 s, although nothing in the cache changed.

The change feed now also watches last writes and sizes, and numbers every
record whose name starts with a cache key. A retry takes a change mark
before it looks on disk and keeps it with its miss. The next retry, while
no <key>.* name has a record from that mark on, repeats the miss without
a file-system call. A created, removed, renamed or rewritten file of the
key sends it back to the disk, and so does a feed that is not reading.

The cache probes line counts these retries as "compute retry unchanged".
The cache index check now runs before the plain-key manifest probe instead of
inside it, so the guard tests/startup_gfx2hlsl_ps57in_check.py reads is the
same expression as on main. Call order and probe counts are unchanged.
@tedin7
tedin7 merged commit affe992 into R0Y00:main Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants