Index literal union members by value instead of scanning pairwise - #102
Merged
Merged
Conversation
JulianaSaran
force-pushed
the
IP-475-large-literal-list-condition
branch
from
September 21, 2026 12:08
115d194 to
e1ed759
Compare
JulianaSaran
marked this pull request as ready for review
September 21, 2026 13:12
robertvansteen
approved these changes
Sep 21, 2026
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.
Description
A condition with a big pasted literal list (
BusinessActivities intersects ['DRI-2090', … ×940])compiles quadratically, twice:
UnionType::joindedups members pairwise (recomputing both shapesper pair), and
UnionShape::ofscans pairwise again on everyshape()call — oneintersectsresolve asks ~4 times. ~880k comparisons per condition; a real product with 34 endorsement
conditions takes 14.2s to compile, so production hits the 30s limit rendering the
publication-checks badge (whose cache can then never warm) and running quote previews. Prod
traces die in each of the two loops (attached as a comment).
Literals are now found through an index keyed by
LiteralShape::valueKey()— a hash keyconsistent with
equals: equal literals always share a key; sharing one only nominates, thesameness judgment still decides (big ints sharing a float image stay distinct, NAN equals
nothing). Non-literal members keep the pairwise scan — only literals arrive in bulk. Same move
as #73; here the key isn't the whole equality, so the bucket verifies.
Type of Change
Related Issues
Relates to IP-475 (internal tracker; production timeouts in Product Catalogue).
Changes Made
LiteralShape::valueKey()— canonical hash key consistent with value equality.DistinctShapes(@internal) — insert-only set under an injected sameness judgment;literals via the key index, everything else pairwise.
UnionShape::ofandUnionType::joindedup through it;joincomputes each type'sshape once instead of once per comparison.
of()≡ naive scan over a hostile pool) and a lockstep law(
ValueEquality::equals(a,b)⇒ same key, with drift sentinels: case, whitespace,unicode composition, ±0.0, the 2^53 boundary, NAN/INF), plus corner pins.
Testing
composer test) — 1,316 tests,zend.assertions=1composer test:types)composer test:infection) — same, relying on CICode Quality Checklist
vendor/bin/pintto format my codeDocumentation
Breaking Changes
N/A — behaviour is pinned identical by the oracle test; the index only changes cost.
Additional Notes
today, no regression.
UnionShape::equalsand union×union overlap remain O(N·M) — follow-up material.hash-consing) — this PR is the minimal step and doesn't block it; the oracle and
lockstep tests carry over unchanged.
🤖 Generated with Claude Code