Repository navigation
perf(build): a source whose size, time and id are unchanged is not read again to name its object - #2702
Conversation
…ad again to name its object Every build read and hashed each source again to name its object, and the 1.4 GB of lifted C up to three times (migrate_stamps, the fingerprint in the log, plan_jobs): planning was 6-7.5 s of a one-file renderer edit's ~31 s build on Windows (A1's table, NotRexed#2693). This is the dev-loop proposal's A5 (NotRexed#2636). build.py keeps a record in <build>/hash_cache.json: for each source its size, modification time and file id, its content's sha1, and the object key worked out from it for each set of flags and headers (kept_part). key_of() returns that key without reading the file while all three match; anything else reads and hashes it as before, and object_key itself, the key's definition, is unchanged, so every object's key and every cache stays as it is. A file written less than 2 s before the record was is read again (git's "racily clean" entries), and a record not trusted for its time loses its keys once the file is read with other content. plan_jobs and the kept list use key_of, the log's fingerprint uses the recorded sha1, and migrate_stamps reads nothing stamped with today's kind of key (its object is in the cache by it). The record is saved after the plan, which make_game.py's builds run; a bare build.py run without HOOKSHOT_TIMES keeps hashing in compile_one as before. Measured on Windows with A1's table: planning 6 s on the first edit build, 2 s on the next two. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
hckrman101
left a comment
There was a problem hiding this comment.
Thanks, this is a clean A5. The key's definition is untouched (key_of computes exactly what object_key does, just from a remembered sha1 when size, mtime and file id all match), so no cached object or kept translation gets renamed, and a miss falls straight back to reading the file. The migrate_stamps shortcut is sound too: an old-kind stamp can't name an object in the cache, so skipping stamps whose object is already cached only skips work that would have done nothing. The 6 s to 2 s planning numbers on the same one-file edit are what I wanted to see, and CI is green.
Two non-blocking points:
- The racy rule's clock (inline):
written_nsis taken when the record is saved, after the whole plan, while each file was stat'd and read earlier, up to the ~6 s planning time before. Git's rule works because the index's time is close to the stat. Taking the time once before the first stat (e.g. inload_hashes, or at the start ofmain) and saving that would keep the 2 s rule exact even on a filesystem with coarse timestamps (exFAT, some network shares). It only matters for an edit landing in the same timestamp tick right after the read, so on NTFS/ext4 it's theoretical, but it's a one-line change. - Nit, the record only grows:
save_hasheskeeps every entry still on disk and everykept_parteach entry has seen.kept_partincludes the headers, so each edit to a header undergpu/vkadds one key to every renderer source that isn't itself touched. It's small per edit, but saving only the entries and keys this build used would keep the file (and the JSON parse every build) bounded.
A Linux dev-loop run would be nice to have in the description when you get a chance (it should behave the same, as st_ino is the inode there), but I don't see anything platform-specific that would change. #2706 also changes build.py (and how the renderer's headers feed the key), so whichever of the two lands second may need a small merge.
|
|
||
| def save_hashes(out): | ||
| """The record of the sources this build saw, for the next one (written atomically; a failure only costs the next build a read)""" | ||
| data = {"scheme": HASH_SCHEME, "written_ns": time.time_ns(), |
There was a problem hiding this comment.
This is the time of the save, after plan_jobs stat'd and read every source (seconds earlier on a first build). For the 2 s rule to mean "the file was read at least one timestamp tick after it was written", this should be the time before the first stat of this build, e.g. time.time_ns() taken in load_hashes and kept for the save. Non-blocking: with ns/100 ns mtimes it's theoretical.
…tRexed#2702) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7fdTPXbwDRohew9qanvbp
Every build reads and hashes each source again to name its object, and the 1.4 GB of lifted C up to three times:
migrate_stamps, the log's fingerprint andplan_jobs. On Windows that planning was 6–7.5 s of a one-file renderer edit's ~31 s build, as #2693's table shows. This is the dev-loop proposal's A5 (#2636).Change
build.pykeeps<build>/hash_cache.json. For each source it holds the size, modification time and file id, the content's sha1, and the object key worked out from it for each set of flags and headers (kept_part).key_of()returns that key without reading the file while all three match, and otherwise reads and hashes the file as before.object_key, the key's definition, is unchanged, so every object's key, every object cache and every player's kept translation stays as it is.plan_jobsand the kept list usekey_of. The log's fingerprint uses the recorded sha1, so its value changes once, and it still says which part changed.migrate_stampsreads nothing stamped with today's kind of key, since that key's object is in the cache.make_game.py's builds run (HOOKSHOT_TIMES). A barebuild.pyrun without it hashes incompile_oneas before.Measured
On Windows (Ryzen 9 3900X, NVMe), three one-file
gpu/vk/vk_draw.cppedit builds in a row, with #2693's table:Each build still compiled the edited file.
Testing
tests/test_build_hash_cache.py(new, 9 cases):object_key, and the next build doesn't read the source;migrate_stampsreads nothing already stamped with today's kind of key;mainwires it in that order.All fail against
main'sbuild.py.The checks that cut functions out of
build.py(test_compile_retry_jobs,test_dlss_sdk_cache,test_shader_stamp_cache) pass unchanged, sinceobject_keyandcompile_oneare as they were.Every check that reads
build.py(39), on Windows, passes apart fromtest_driver_cache_folder,test_fpx_stickyandtest_linux_update, which fail the same way withmain'sbuild.pyhere.Not tested: Linux. The file id there is the inode, as
os.statgives it.🤖 Generated with Claude Code