perf(vk): the pipeline notes are stored without their zeros #3027
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3027
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:perf/note-pack"
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?
Summary
A pipeline note is the draw state as it lies in memory, about 27 KB of which about 105 bytes are not zero. After a preparation
longshot_pipelines.binis about 1.05 GB (38,774 notes here), 99.7% of it zeros. Each note is now stored as its runs of non-zero bytes.On top of
mod-api(#2822). See #1649: with #3023 this covers what it proposes, so it can be closed once both are in.Read first:
gpu/vk/note_pack.h(the format, the walk, the append and the conversion), thennotes_pack_file,notes_open_locked,pipe_notes_refsandpipe_note_atingpu/vk/vk_draw.cpp.[length][runs].PipeNoteandkNotesFormatare unchanged.Testing
Tested: Linux, RTX 3090, NVIDIA 620.70.06, head
355a203bc9onmod-apid6b5bd5123.dev.py smokePASS twice: the first start logsstored without their zeros, 1003 MB made 7 MB, and both find38774 noted pipelines. Those two confined runs had no kept programs, so built nothing from the notes.HOS_SANDBOX=0(in play, then the Market): 38,774 notes found, 9,346 graphics pipelines made at load from the packed records (0 not in a cache), 5,196 loads, no read failures.test_pipelines_outlive_cache_format.note_pack.hon a copy of a real file: all 38,774 records read back byte for byte, 1052.5 MB to 7.6 MB, converted in 1.36 s.mise run test(before that last fix): 825 passed, 35 failed, 12 skipped; the same 35 names fail on untouchedmod-api582b6a1a(not rerun on the newer base):test_astc_upload_chunking,test_async_astc_upload_chunks,test_bind_memo,test_blocks_at_start,test_direct_buffer_writes,test_drawn_page_map,test_draw_stream_visibility,test_early_split_before_draw,test_flat_map,test_fsr_image_retirement,test_fsr_uniform_ownership,test_image_reaper_threads,test_import_reach,test_late_fix_build,test_lifter,test_menu_i18n,test_mirror_bookkeeping,test_pass_barrier,test_present_acquire_ahead,test_present_image_free,test_readback_timeout_reuse,test_recorder_sync,test_recording_admission,test_report_words,test_staging_burst,test_target_retention,test_tex_desc_memo,test_text_keyboard_policy,test_ub_snapshot_default,test_ub_snapshot_gpu_writes,test_vk_wb_cpu_words_fast,test_vram_compact,test_wb_diff_stale_shadow,test_wb_pending_capture,test_wrote_regions. After the fix: the note tests, 15 passed.dev.py vkbuilds the renderer.tests/test_note_pack.py: round trips, damaged runs, conversion, a part record, a length no record has, a write that fails.Still to test:
Measurements
Verdict: the notes take 139x less disk. Frame rate was not measured.
Setup: Linux, RTX 3090. Size and conversion: the harness above on a copy of one file. The start's walk of the notes: the log's
the notes' file walked 1 times this start, in N ms, from different runtimes and not interleaved, so rough.mainitself was not run: the first column is the unpacked format, whichmainand this PR's base share, measured on builds of the base.b40214d2bb355a203blongshot_pipelines.binRisks
Checklist
This PR's base is
mod-api: readmainbelow as the base.Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.🤖 Generated with Claude Code
WIP: perf(vk): the pipeline notes are stored without their zerosto perf(vk): the pipeline notes are stored without their zerosRecommendation: Request changes. A read error during the packed-file scan can truncate valid pipeline notes, and concurrent conversions can corrupt the replacement file. The existing checks also need updating, and neither the claimed space saving nor the startup cost has been measured.
Stores pipeline notes as runs of non-zero bytes and converts existing files to reduce cache size. It adds a conversion step and packed-record reads at startup and during pipeline loading; their cost and the actual saving are unmeasured.
Blocking (4): must change before merging.
gpu/vk/note_pack.h:118: Do not truncate the file when the scan fails to read or seek. (more on the line) Do: Return a separate scan status for I/O failures and only resize after positively identifying a partial trailing record; leave the file untouched on a failed scan.gpu/vk/note_pack.h:138: Conversion uses one predictable staging file without coordinating with other processes that share the cache. (more on the line) Do: Serialize conversion across processes or use unique staging files and an atomic replacement protocol that verifies the source has not changed before replacing it.gpu/vk/vk_draw.cpp:2658: A failed packed-record write is ignored after the key has been marked as noted, and subsequent records are still appended. (more on the line) Do: Check the write and flush results, stop appending or roll back to the last complete record on failure, and do not report the key as successfully recorded.gpu/vk/vk_draw.cpp:14546: Update the existing source-cut checks for the changed readers and add behavioral coverage for the packed format. (more on the line) Do: Update the affected fixtures without weakening their existing cases, and add game-free round-trip, conversion, damaged-record, partial-tail and write-failure cases that exercise the real implementation.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1, L2, L3 and L4.Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven. The PR reports a 1.05 GB existing file with 38,774 notes, but provides no size or timing results for the packed file, conversion, or subsequent starts.
Other systems: The format is shared by preparation, startup indexing, pipeline loading and play-time note writes on Windows and Linux, including Steam Deck and all GPU vendors. No game or platform runs are reported. Older builds and reverts will discard the packed notes as described in the PR.
Switches: None added, changed or removed.
Reviewed:
a95f7d7d65against582b6a1abf: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md and the pull request template; docs/review-checklist.md and the adjacent Tooling checkout were absent. Read the complete diff, commit message, note_pack.h and vk_pipelines.h, and the changed sections and relevant callers in vk_draw.cpp. Inspected the affected source-cut checks and searched related readers and path handling. The rest of vk_draw.cpp and the full test suite were not read. No recorded runs or translations were supplied.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code, tests or project scripts were run. The PR reports no testing.
Overlaps and merge order: The PR is based on #2822 and identifies #3023 as related; no independent overlap search was available with the network closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as HumanBean took it out of WIP. Nothing was run; a maintainer decides.
@ -0,0 +115,4 @@FILE* f = std::fopen(path.c_str(), "rb");if (!f) return false;walk(f, n, end);std::fclose(f);L1 (blocking): Do not truncate the file when the scan fails to read or seek. walk returns the last position reached for both a partial tail and an I/O failure, so cut cannot distinguish them.
When: If a packed file has valid records but a seek or read fails partway through, walk stops at that record and cut resizes the file to that point, permanently deleting the remaining valid notes.
Do: Return a separate scan status for I/O failures and only resize after positively identifying a partial trailing record; leave the file untouched on a failed scan.
@ -0,0 +135,4 @@return false;}const std::string fresh = path + ".packing";FILE* out = std::fopen(fresh.c_str(), "wb");L2 (blocking): Conversion uses one predictable staging file without coordinating with other processes that share the cache.
When: If two game processes convert the same old notes file at once, both open the same .packing file with truncation and write through separate handles. One can rename it over the original while the other is still writing, leaving the packed notes corrupted or incomplete.
Do: Serialize conversion across processes or use unique staging files and an atomic replacement protocol that verifies the source has not changed before replacing it.
@ -2610,3 +2656,3 @@if (!note_file) notes_open_locked(nullptr);if (!note_file || !note_new_locked(key)) return false;fwrite(rec.get(), sizeof(PipeNote), 1, note_file), fflush(note_file);if (note_file_packed) note_pack::write_record(note_file, (const uint8_t*)rec.get(), sizeof(PipeNote));L3 (blocking): A failed packed-record write is ignored after the key has been marked as noted, and subsequent records are still appended.
When: If the disk fills partway through a record and space later becomes available during the same run, later notes are appended after the incomplete body. Readers stop at the damaged record or consume part of a later one, so those later pipelines are not recovered at the next start.
Do: Check the write and flush results, stop appending or roll back to the last complete record on failure, and do not report the key as successfully recorded.
@ -14478,0 +14543,4 @@auto full = std::make_unique<PipeNote>();std::vector<uint8_t> scratch;for (int64_t at = 16; packed;) {if (_fseeki64(f, at, SEEK_SET)) break;L4 (blocking): Update the existing source-cut checks for the changed readers and add behavioral coverage for the packed format.
When: test_note_refs_once expects three seek calls in the extracted reader, but the packed loop adds a fourth; its fixture rejects the changed function before testing. Other extracted fixtures also lack the new packing dependencies.
Do: Update the affected fixtures without weakening their existing cases, and add game-free round-trip, conversion, damaged-record, partial-tail and write-failure cases that exercise the real implementation.
a95f7d7d6583adeeb6ae83adeeb6ae355a203bc9All four blocking points are addressed in the new head.
note_pack::walknow says how it ended.cut_tailresizes only for a part record or a length no record has; on a read or seek failure the file is left as it is and nothing is added to it.note_pack::appendchecks the write and flush, closes and cuts back to the last whole record; the key is not kept as noted and nothing more is added that run.tests/test_note_pack.pycovers round trips, damaged records, the partial tail, conversion and a failed write.🤖 Generated with Claude Code