Repository navigation
perf(diff): take the snapshots from the Unit table and read only the units whose hash changed - #2022
Draft
italo-kalil-cesar wants to merge 4 commits into
Draft
italo-kalil-cesar wants to merge 4 commits into
italo-kalil-cesar wants to merge 4 commits into
Conversation
mxcli diff spent most of its time (about 18 s of 26 s on a 3,100-unit project, Windows) copying the project one file at a time, then hashing the files next to the model and removing the scratch folder one file at a time. - copyProject: regular files are copied by a pool of workers (directories and symlinks are still created in walk order). - TakeSnapshot: the files next to the model are hashed by a pool of workers. - Scratch.Close: the first three levels of the scratch folder are removed in parallel. - packages/ (deployment packages exported by Studio Pro) joins the skipped directories: build output that exec never reads or writes. - MXCLI_DIFF_TIMING=1 prints the time of each stage of a diff to stderr. Measured on one project (3,138 units, ~430 MB outside the skipped directories): diff of a one-statement script 30.8 s -> about 13 s; same output as before on the scripts tried. Tests: the copy skips the build directories and copies every file, the parallel removal removes the tree, the file hash is SHA-256. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
For a tool that has to decide on the result of a diff without parsing the text: refused, preflight, execError, failures, units, documents, files and summary. A script exec would refuse reports refused and summary.writesNothing. Docs: the diff page gains a JSON output section, the flag help and the --json refusal hint name the format, and CHANGELOG has the entry. Tests: a modified document and file are reported with the right kinds and summary; a refused script has writesNothing and empty (not null) lists. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ng files For a caller that only needs to know which units changed between two moments: the Unit table's ContentsHash (the SHA-256 of the unit's file) and the name the type index holds. MPR v1 has none (nil), and the caller reads what it needs. The test checks every stamp against the file it describes, on a warm index with no unit file opened. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ash changed diff took two snapshots that each read every unit file of the scratch copy. Run now takes them from the table (type, name, place and ContentsHash, via mpr.UnitStamps) and Compare reads a unit's bytes only when the two hashes differ, the unit moved, or it was added or removed. What a unit was before is read from the project the copy was made from, since the copy is rewritten by then. Units the reader cannot stamp (MPR v1, packages) are read as before, a row without a hash is compared by its bytes, and a unit whose bytes cannot be read is reported as rewritten rather than dropped. TakeSnapshot is unchanged. Tests (PedApp fixture): the table snapshot has the same units as the eager one and reads no file; Compare over an added, removed, rewritten and moved unit returns the same changes, ids, kinds and bytes as the eager Compare while reading only the changed units; with every hash blanked it still matches. The existing diff-versus-exec tests run through the new Run. Measured on a 3137-unit, 1 GB project (MXCLI_DIFF_TIMING, 3 runs each, alternating): snapshot-before 3.1-5.8 s -> 0.6 s; snapshot-after 1.2-2.0 s -> 0.5-0.7 s; exec 1.5-3.3 s -> 2.7-3.0 s (the old eager snapshot warmed the copy's cache); total 15.3 / 15.9 / 22.5 s -> 13.8 / 13.2 / 12.4 s. The copy (6.3-6.9 s) and cleanup (1.5-2.1 s) are untouched. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #2014
Opened as a draft, stacked on the diff-parallel PR (#2021, branch
pr/diff-parallel): its two commits come first in this branch. Review only the last two. The gain here is small (see below), so the issue asks whether you want it at all.What was wrong
mxcli difftook two snapshots of the scratch copy, each reading every unit file (3.1-5.8 s and 1.2-2.0 s on a project of about 3 thousand units, 1 GB).What changes
mpr: UnitStamps gives each unit's name and ContentsHash without opening files:Reader.UnitStampsreturns, for an MPR v2 project, each unit's name and the Unit table'sContentsHash(SHA-256 of its file) from the table and the type index. MPR v1 returns nil and the caller reads what it needs.scriptdiff: snapshot from the Unit table; read only the units whose hash changed:Runtakes both snapshots from the table;Comparereads a unit's bytes only when the two hashes differ, the unit moved, or it was added or removed. The bytes from before the script come from the project the copy was made from, since the copy is rewritten by then. Units the reader cannot stamp (MPR v1, packages) are read as before; a row without a hash is compared by its bytes; a unit whose bytes cannot be read is reported as rewritten, never dropped. The publicTakeSnapshotis unchanged. CHANGELOG has an entry.Honest size of the gain
Same project,
MXCLI_DIFF_TIMING, 3 runs each, alternating: snapshot-before 3.1-5.8 s -> 0.6 s; snapshot-after 1.2-2.0 s -> 0.5-0.7 s. But exec inside the diff got about 1.2 s slower (1.5-3.3 s -> 2.7-3.0 s): the old eager snapshot warmed the copy's cache, which exec then used. Total 15.3 / 15.9 / 22.5 s -> 13.8 / 13.2 / 12.4 s, so about 2 to 3 s net out of about 15 s. The copy (about 6.5 s) and the cleanup (about 1.6 s) are unchanged and are now most of the time.Tests
snapshot_table_test.goon the PedApp fixture: the table snapshot has the same units as the eager one and reads no file;Compareover an added, removed, rewritten and moved unit returns the same changes, ids, kinds and bytes as the eagerComparewhile reading only the changed units; with every hash blanked it still matches.reader_unit_stamps_test.go: every stamp equals the file it describes on a warm index with no unit file opened; MPR v1 gives none. The existing diff-versus-exec tests run through the newRun. The built binary gives the samediff --format jsonreport as the previous branch on the same script.go test ./mdl/scriptdiff ./modelsdk/mpr: the set of failing tests is identical to main's (Windows: unit-contents.db still open at TempDir cleanup,TestSyncWithDisk_Issue2121; see test(mpr): close the readers the test helpers open, so unit-contents.db can be removed on Windows #2016); no new failure.Run locally
Run on Windows without make; the equivalents were run by hand:
go build ./...: cleango veton the touched packages: cleangofmt -lon the touched files: emptygo test -timeout ...on the touched packages: see Testsmake check-test-timeouts,make check-findings: not run (bash and make are not available here); no Makefile or findings file is touchedStudio Pro validation
Not run. diff writes nothing to the project.
Agentic testing
Not run.