perf: optimize diff and graph algorithms matching official git client #55

merged colechristensen cole.christensen@gmail.com wants to merge perf/diff-and-graph-optimizations into main

Summary

Optimizes tree diffing, Myers line diffing, and graph reachability queries based on the official Git C client architecture:

  1. Myers Diff Line Interning & Single-Pass Hunk Builder (ExGitObjectstore.Diff.Myers, ExGitObjectstore.Diff):

    • Interns unique line strings to small integer IDs (0..N-1) during diffing so the Myers snake traversal executes single-cycle BEAM integer comparisons instead of comparing full binary terms.
    • Replaced multi-pass Erlang :array tree building with single-pass tuple indexing in hunk construction.
  2. Single-Pass Decompression & Size Guard (ExGitObjectstore.Diff.diff_blobs/4):

    • Added :max_bytes size limit support to diff_blobs/4 so oversized files are stubbed immediately during single read without redundant decompression.
  3. Scheduler Parallelization (ExGitObjectstore.Diff.diff_commits/4):

    • Diffing individual files within a commit diff is now parallelized across BEAM schedulers using Task.async_stream/3.
  4. Two-Pointer Tree Merge Walk (ExGitObjectstore.Diff.diff_trees/3):

    • Replaced MapSet.union + Enum.sort with a two-pointer linear merge walk over sorted tree entries matching Git’s tree-walk.c:traverse_trees.
  5. Early-Exit Graph Traversal (ExGitObjectstore.Graph.Fallback):

    • ancestor?/4 now performs an early-exit BFS stopping immediately once the target commit is reached.
    • ahead_behind and ahead_behind_many stop following parent branches the moment they reach commits already known to belong to the base history.
Created Sep 01, 2026 at 03:55 UTC | Merged Sep 01, 2026 at 04:33 UTC by colechristensen cole.christensen@gmail.com