[pr-fix][startup][shaders] Checkpoint early pipeline keys independently #235
Loading…
Reference in a new issue
No description provided.
Delete branch "andrewpozdnakov7-jpg/Darner:port/1989-checkpoint-early-pipeline-history"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (optional)
What it changes
The early list can stay unsaved when a run first uses keys and the native pipeline library never saves. Record new first-use keys independently. Coalesce updates on a background thread, merge the existing snapshot under a cache-local lease, and keep failed checkpoints dirty for retry.
Restores locally saved VIctory-NVIDIA work from December 1, 2026. Previous review: CodeFloe #390. Adapted by andrewpozdnakov7-jpg (GitHub profile).
How it was tested
17f43b3onf3840d7.2668ae5keeps library-coupled checkpointing by default and enables independent saves withDARNER_EARLY_CHECKPOINT=1. With the new mode on, the exit checkpoint retries a busy cache lease for up to 200 ms. A real Windows sharing-mode fixture verified lease release and merged keys, and precedence cases verified that only1enables the mode. The focused GPU crate type check and asset policy passed.Checklist
Checked for overlap
I tested the mixed-version writer case on Windows at
17f43b3de30d9800a3f30d167b1c0c13336c3a45and its parentf3840d73d3504c30218debfbc8795b9225447317. Two processes loaded the same seedPbefore either saved. The harness compiled each revision’s observation, save, atomic-write and reader functions, used synthetic keys and supplied no GPU library.C, then parent savesM: fresh readers seeP,M. The parent overwritesC.M, then candidate savesC: fresh readers seeP,M,C.After the overwrite, a checkpoint in the still-running candidate with no new keys left the file at
P,M. RecordingDand checkpointing restoredCand preservedM, producingP,M,C,D. This matters when two versions write to the same cache directory. Normalplayguards against a second run from the same home. No gameplay or performance measurement was involved.Code-read review of
17f43b3. I did not build or run it, and I looked only at this diff, not at other open PRs.The problem is real. On main,
early-pipelines.txtis written only insidesave_inner, after a library save and only ifUSED_CHANGEDis set or bytes were written. A run that loads every pipeline from the library loses its first-use keys if it crashes. The handshake betweenchanged()and the worker (dirty is set beforeRUNNINGis taken, and the worker re-checks dirty underRUNNING) looks right to me. Three things I would look at before merging:1. Title threads wait on a full clone of the
USEDset, about once a second during the opening.checkpoint()callsHISTORY.flush(dir, || super::used().iter().flatten().cloned().collect())(early_history.rs). TheUSEDguard is held while up toEARLY_MAX(100,000) strings are cloned. Title threads take the same mutex innote_used,wanted_earlyandlisted(make.rs:733,765,928,1098,1114). While new keys keep arriving, the worker repeats this every second, and each round also re-reads, sorts and rewrites the whole file. Main did the clone once per library save. The test comment on this PR says no gameplay or performance measurement was involved, so nothing shows this is cheap. Suggestion: keep a small "new since the last checkpoint"Vec<String>(pushed innote_used, drained by the worker) and merge only that into the file. Otherwise a frame-time comparison on a heavy scene would settle it.2. The exit checkpoint can lose keys that main would have written.
save_inner(true)now callsearly_history::checkpoint()(library.rs:1348). The lock file is opened withshare_mode(0), so if another process holdsearly-pipelines.lockat that moment the open fails at once.checkpoint()logs at debug level and returns false, and the process ends with the keys unsaved. Main wrote the file at exit whenever a new key had been added. The window is small, but this is the one write that must not be skipped: please retry for a short time (a few tries over a second or so) in the final call, aswriter(dir, wait)does for the library.3. New behaviour, no switch.
It adds a thread, a new persistent file (
early-pipelines.lock) and union-merge semantics for the early list. Upstream's habit for new behaviour is a default-off switch, or the maintainer's explicit OK. Please say which in the body. superhero-520's mixed-version test (an older build overwriting a newer build's keys) is worth stating in the body.Smaller points: the
earlycount in the "host pipeline library saved" log is now the in-memory count, not what was written; leftoverearly-pipelines.txt.tmp-<pid>-<n>files after a kill are not swept (remove_leftoversonly handleshost-pipelines.tmp*), and writes are now far more frequent;early_history.rsis not a single-word file name and its//!line does not give the why with evidence (AGENTS.md conventions).The unit test covers the merge and the held-lease failure well. Nothing covers the worker thread or the cost.
This comment was written with AI assistance (Claude Code).
I measured the
USEDlock interval discussed above at17f43b3de30d9800a3f30d167b1c0c13336c3a45. On a Ryzen 7 5800H with Windows and optimized Rust 1.98.1, a standalone probe used the PR'sMutex<Option<HashSet<String>>>and its clone intoVec<String>. Timing started after lock acquisition and ended immediately after dropping the guard. Clone destruction, file I/O, and the subsequentBTreeSetmerge were outside the timed interval.The smaller counts match the lengths of two local early-pipeline indexes. The largest is the code's cap. Each row pools 180 observations across three processes after warm-up, with sizes interleaved. A separate workspace test was running on the host. These figures measure the copy while the lock is held. Gameplay frame times and contention experienced by a drawing thread remain unmeasured.
Thanks for the review and the lock-hold measurements. The follow-up in
2668ae5keeps the current library-coupled save by default. Independent checkpoints now requireDARNER_EARLY_CHECKPOINT=1, so the background worker and its set clone are limited to that mode.With that mode enabled, the exit checkpoint waits up to 200 ms on a sharing violation and warns if the lease stays busy. A Windows fixture held and released the real lease, then checked that both the existing and newly observed keys survived. The focused GPU crate type check and asset policy passed.
The synthetic timings are useful at the largest key counts. I am keeping them as lock-hold measurements in this review, since gameplay impact was outside the probe.
If folding the follow-up into another commit, please retain the Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.