Repository navigation
Conversation
This was referenced Nov 25, 2026
…irst error Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
…the first error Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Roman3349
force-pushed
the
perf/fail-fast-branches
branch
from
December 4, 2026 14:37
eb79117 to
6a361d2
Compare
6 of 12 tasks
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
In strict mode, every branch of
oneOfandanyOfand the subschemas ofnotandifwere evaluated completely, although only their validity is used: the errors of the branches are discarded when theoneOforanyOfpasses, and the errors ofnotandifare never reported. With schemas that select between several large alternatives, this is where most of the time goes. In the GeoJSON schema of the jsonschema-benchmark, the rootoneOfhas 9 branches andgeometryanother 7, so the coordinates of each geometry are walked through in about 6 branches, of which only one matches.The branches are now evaluated up to their first error. When the
oneOforanyOffails, its branches are evaluated once more to collect their errors, so the reported errors are the same as before. This is skipped as well when the errors are not needed either, for example in a branch of an outeroneOf.Collecting all errors stays the default. The new
Constraint::CHECK_MODE_FAIL_FASTstops the whole validation at its first error and reports only that one, for when only the validity of the data is needed.Changes:
Constraints\EvaluationState: new, holds whether the constraints may stop at their first error. It is shared by all factories of one evaluation, including the ones the strict mode draft constraints create for nested schemas.Constraints\Factory:startFailFast(),stopFailFast()andisFailFast()to switch it for the evaluation of a subschema. It stays off when the check mode modifies the value (CHECK_MODE_APPLY_DEFAULTS,CHECK_MODE_COERCE_TYPES) or throws on the first error (CHECK_MODE_EXCEPTIONS), as every constraint has to be evaluated then.OneOfConstraint,AnyOfConstraint,NotConstraintandIfThenElseConstraint(forif) evaluate their subschemas up to the first error.ItemsConstraintandPropertiesConstraintthe remaining items and properties, once an error is found and only the validity is needed.Constraint::CHECK_MODE_FAIL_FAST(0x00000400) andValidator: the new check mode, documented in the README.The
perfandfeatparts are in separate commits.Validation of the 500 GeoJSON instances with the benchmark's harness for this library (
implementations/justinrainbow/main.php, strict mode):mainRelated Issue
None
Type of Change
Checklist
Additional Notes
FailFastTestchecks that the errors reported by default are exactly the ones ofmainfor failingoneOf,anyOf,not,ifand nestedoneOfin all three drafts, and thatCHECK_MODE_FAIL_FASTreports a single error.This works together with #926, which avoids instantiating the constraints of keywords a schema does not have. With both, the first 100 GeoJSON instances take 5.6 s instead of 26.7 s on
main(11.0 s with #926 alone, 11.4 s with this PR alone). Both changecheckForKeyword()of the draft constraints, so whichever is merged second needs a small rebase.#971 (Draft 2020-12) uses the next bit,
0x00000800, forCHECK_MODE_FORMAT_ASSERTION.