Skip to content

perf: reuse a reference's quick hash before building its schema - #670

Open
josephaxisa wants to merge 1 commit into
pb33f:mainfrom
josephaxisa:perf/quick-hash-cyclic
Open

josephaxisa wants to merge 1 commit into
pb33f:mainfrom
josephaxisa:perf/quick-hash-cyclic

Conversation

@josephaxisa

Copy link
Copy Markdown
Contributor

Follow-up to your #667 note that quick hash loses to no quick hash on cyclic docs.

With UseSchemaQuickHash, each non-circular reference built its target schema before checking SchemaQuickHashMap, so most builds were wasted: on stripe.yaml with 300 type edits, 3,954 of 5,602 found the hash already cached. This computes the cache key from the proxy (quickHashKeyOf, split out of quickHashKey) and builds only on a miss. $ref nodes still go through Schema().

Quick hash on, median of 8 interleaved runs:

main this PR
stripe.yaml, 300 edits 195ms, 254MB 172ms, 222MB
docusignv3.1.json vs itself 203ms, 342MB 99ms, 155MB
asana.yaml vs itself 27ms, 35MB 19.5ms, 23MB

Quick hash off is unchanged (123ms), so quick hash is still slower on Stripe, but by less.

Same results as main: identical openapi-changes change sets on Stripe release pairs, full suite passes, plus a test that a cyclic spec reports the same with quick hash on and off.

With UseSchemaQuickHash, every non-circular reference built the schema it
points to and only then found its quick hash in SchemaQuickHashMap. Many
references point at the same schema, so most of those builds were thrown
away: comparing test_specs/stripe.yaml with a copy carrying 300 edits,
3,954 of 5,602 reference builds during CompareDocuments found the hash
already cached.

Work out the key the built schema would use from the proxy and look it up
first, building only on a miss. The key comes from the same function the
schema uses. A node that is itself a $ref is re-attributed while building,
so it still goes through Schema().

With quick hash on, CompareDocuments takes about 12% less time and 13% less
memory on the stripe.yaml comparison, and about half on docusignv3.1.json.
Quick hash off is unchanged.
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3406d80) to head (90b107e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #670   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          309       309           
  Lines        39279     39294   +15     
=========================================
+ Hits         39279     39294   +15     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant