Skip to content

Speed up schema diff reporting with bounded comparison - #7

Merged
inxilpro merged 1 commit into
mainfrom
claude/sweet-bell-nfjv3m
Sep 20, 2026
Merged

inxilpro merged 1 commit into
mainfrom
claude/sweet-bell-nfjv3m

Conversation

@inxilpro

Copy link
Copy Markdown
Contributor

Summary

Replaces PHPUnit's full-document differ (which takes ~15 minutes on the Linear schema) with a bounded diff that walks both sides once, re-syncs over short runs of changes, and stops after a few hunks. This allows schema validation tests to complete in seconds rather than timing out.

Changes

  • Added BoundedDiff support class (tests/Support/BoundedDiff.php): A line-by-line differ that:

    • Walks both documents once instead of weighing every line against every other
    • Re-syncs when lines match again (within a configurable window)
    • Stops after a configurable number of hunks
    • Truncates long runs of changes to avoid overwhelming output
    • Completes in milliseconds even on 40,000-line documents
  • Added BoundedDiffTest (tests/Feature/BoundedDiffTest.php): Comprehensive test coverage including:

    • Matching documents
    • Single-line changes
    • Insertions that shift subsequent lines
    • Hunk limits
    • Documents that never re-sync
    • Performance validation (40,000 lines in <5 seconds)
  • Updated SchemaFetcherTest to use BoundedDiff:

    • Compares schemas by hash first (fast path for no changes)
    • Only describes first few differences when schemas diverge
    • Replaces assertion with descriptive failure message
  • Reduced CI timeout from 30 to 15 minutes: The bounded diff eliminates the need for extra time to render a 15-minute diff.

Implementation Details

The BoundedDiff algorithm:

  1. Walks both sides in parallel, advancing when lines match
  2. When lines diverge, searches forward up to window lines for a re-sync point (3+ matching lines)
  3. Emits a hunk with context lines and truncated change bodies
  4. Stops after max_hunks hunks or when no re-sync is found
  5. Reports line numbers and counts to help locate changes in large documents

https://claude.ai/code/session_01XyfyD8QtJPci6seYNVdBXx

test_it_matches_the_schema_committed_to_this_repository compared two
copies of the whole Linear schema with assertSame. On a match that costs
nothing, but on a mismatch PHPUnit's differ weighs all ~35,800 lines of
one document against all ~35,800 of the other, which took about fifteen
minutes to print. In CI that pushed one job to 14:15 and timed the other
five out mid-diff, so they were reported as cancelled and a real bug
looked like flaky infrastructure.

The test now matches on a hash and, when the hashes differ, describes the
first few differences with BoundedDiff: a line diff that walks both sides
once, re-syncs over short runs of added or removed lines, and stops after
five hunks. The message still names the concrete drift, including the case
this caught, @deprecated(reason:) dropped from input fields under
webonyx/graphql-php below 15.34.1.

With the schema mismatched, the test now fails in 1.7 seconds. The CI
timeout goes back to 15 minutes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XyfyD8QtJPci6seYNVdBXx
@inxilpro
inxilpro merged commit 3a22503 into main Sep 20, 2026
38 checks passed
@inxilpro
inxilpro deleted the claude/sweet-bell-nfjv3m branch September 20, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants