fangorn/ex_git_objectstore
public
ref:783dab7b2eadd5f40234c35613e5c5ad4dd5b838
perf(diff): remove redundant V-table probes from the Myers bisect loop
Profiling the fangorn/hephaestus#74 pull-request diff (fangorn/anvil#367)
put ~77% of diff CPU in the Myers middle-snake search, with two constants
larger than they need to be:
* `vget`/`vput` were not inlined. On that diff `vget` is called 3.6M
times; eprof attributed 23.08% of total runtime to it against 12.26%
for the `:atomics.get/2` it wraps. `@compile {:inline, ...}` folds the
wrapper away.
* `forward_sweep`/`reverse_sweep` read both neighbouring diagonals in the
`cond` guard and then re-read the winner in the selected branch — three
or four V probes where two suffice. Binding them once removes roughly
one probe in three from the hottest loop in the module.
Neither touches the algorithm. The output is unchanged and the O(ND) bound
(Myers 1986 §4b) is unchanged; this is strictly less work per diagonal step.
Measured over every text file in the hephaestus#74 three-dot diff
(118 files, median of 5 runs):
before 66.8 ms slowest single file 48.2 ms
after 60.3 ms slowest single file 40.8 ms
~10% overall, ~15% on the hot file. Smaller than eprof suggested, because
eprof's per-call instrumentation inflates the apparent cost of small
functions — the honest number is the wall-clock one.
Also adds MyersOptimalityTest: 900 randomized cases checked against a
dynamic-programming LCS reference for both soundness (the script rebuilds
both inputs) and optimality (the script is genuinely shortest). The
existing tests are hand-written cases and would not catch a bisect that
still produces a valid but non-minimal script, which is exactly the failure
mode an optimization here can introduce. Verified to pass before and after.
Refs fangorn/anvil#367
SHA:
783dab7b2eadd5f40234c35613e5c5ad4dd5b838
Author:
CI <ci@fangorn.io>
Date:
2026-07-29 16:28
Parents:
228bb1e
2 files changed
+176
-8
| Type | ||
|---|---|---|
|
|
lib/ex_git_objectstore/diff/myers.ex | +19 −8 |
|
||
|
|
test/ex_git_objectstore/diff/myers_optimality_test.exs | +157 −0 |
|
||