Skip to content

Hoist loop-invariant location strings out of validation loops - #152

Open
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:hoist-location-strings
Open

Hoist loop-invariant location strings out of validation loops#152
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:hoist-location-strings

Conversation

@jnbdz

@jnbdz jnbdz commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #75

Motivation

As reported in #75, SchemaValidatorImpl.validate rebuilt loop-invariant location strings (schemaLocation + "/anyOf/" + i, instanceLocation + "/" + Pointers.encode(key), …) on every iteration of its validation loops — the hot path for large instances. The codebase had already started this pattern in one spot (keywordLocation2 in the additionalItems loop).

Changes

  • Hoist the loop-invariant schema/base/instance location prefixes in front of each loop (anyOf/allOf/oneOf, propertyNames, dependentSchemas, dependencies, properties, patternProperties, additionalProperties, unevaluatedProperties, prefixItems, items, additionalItems, contains, unevaluatedItems).
  • Reuse the Pointers.encode(key) result where it was computed up to three times per iteration.
  • Concatenations that only run on the error branch are intentionally left inline: hoisting them would compute strings even for fully valid instances.

No behavior change; the full suite (including the official test-suite TCK) passes unchanged.

Note

While making this change I noticed the contains loop iterates with j but builds its instance location from the outer i (instanceLocation + "/" + i). This looks like a pre-existing bug in the reported error location; this PR deliberately preserves the current behavior. Happy to file/fix it separately if you agree it's wrong.

The validator rebuilt schema/base/instance location prefixes such as
schemaLocation + "/anyOf/" on every loop iteration. Hoist the
loop-invariant concatenations in front of the loops and reuse the
encoded property key where it was computed several times per iteration.
No behavior change.

Fixes eclipse-vertx#75
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.

Move the appending of slashes out of loops

1 participant