Repository navigation
startup: answer draw and Dispatch cache probes from the cache index - #3570
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_lockheld: 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>.txton the retry schedule.This PR extends
src/startup_stubs/cache_index.h(#3433, #3436). Those probes now ask the index first and skip thedisk for an absent name. An unchanged compute manifest miss is repeated without I/O.
ReadDirectoryChangesWon the cache (top level: names, last writes, sizes) and thenmakes 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 thedisk. A write that finds such a name present is counted as a contradiction.
<key>.txt,<key>.cs.hlsl): answered absent only while the feed is reading, and only if it wasreading before the listing began. A dropped batch or any feed error sends them back to the disk.
<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_checkand controls, judged by their CTest PASS/FAIL regular expressions: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_checkandbidi_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..cs.hlslprobes; every other probe was a hit on disk. No file was created inthe cache during these runs, so the feed read 0 records.
draw_lockfor 9.5 s of each 10 s after thestop (manifest load: at most 0.6 s per 10 s).
.cs.hlslprobes;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_lockfor 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.
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.