Skip to content

Jsonschema-rs backend#478

Merged
p1c2u merged 4 commits intomasterfrom
poc/rust-backend
Mar 1, 2026
Merged

Jsonschema-rs backend#478
p1c2u merged 4 commits intomasterfrom
poc/rust-backend

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Feb 27, 2026

Benchmarks:

  • github-jsonschema-rs.prof
    • total_tt: 10.77s
    • total_calls: 19.43M
  • github-jsonschema.prof
    • total_tt: 18.24s
    • total_calls: 42.47M

Result:

  • jsonschema-rs backend is about 1.69x faster (~41% lower total_tt)
  • and does ~23.0M fewer calls (~54% fewer).
    Where the win comes from:
  • Huge reductions in Python jsonschema keyword/descend/ref paths:
    • jsonschema.validators.descend: 10.86s -> 3.22s
    • jsonschema._keywords.properties: 10.87s -> 3.22s
    • jsonschema.validators.iter_errors: 10.89s -> 3.24s
    • jsonschema._keywords.ref: 10.74s -> 3.09s
  • Some costly keyword handlers disappear entirely with Rust path in this run:
    • patternProperties, oneOf (in Python jsonschema stack).
      Cost introduced by Rust path is small in profile:
  • rust_adapters.iter_errors: ~0.058s
  • native jsonschema_rs.Validator.validate: ~0.058s

Relates #477

@p1c2u p1c2u force-pushed the poc/rust-backend branch 6 times, most recently from c9f2cfa to 3b0e126 Compare February 28, 2026 23:03
@p1c2u p1c2u changed the title Rust backend Jsonschema-rs backend Feb 28, 2026
@p1c2u p1c2u force-pushed the poc/rust-backend branch 5 times, most recently from 2c01b5c to c1510d5 Compare March 1, 2026 01:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional jsonschema-rs-powered schema validation backend to improve performance, with environment-based selection and CI coverage to ensure both backends behave acceptably within this codebase.

Changes:

  • Introduces backend selection (auto / jsonschema / jsonschema-rs) via OPENAPI_SPEC_VALIDATOR_SCHEMA_VALIDATOR_BACKEND and wires it into schema validator construction.
  • Adds a jsonschema-rs adapter layer and updates CLI behavior/output for backend-specific subschema-details handling.
  • Updates tests/docs/CI to support both backends and loosen assertions where error strings differ.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
openapi_spec_validator/settings.py Adds settings field + normalization for backend selection.
openapi_spec_validator/schemas/backend/init.py Implements backend selection logic and validator factory routing.
openapi_spec_validator/schemas/backend/jsonschema.py Adds a small factory for the Python jsonschema backend.
openapi_spec_validator/schemas/backend/jsonschema_rs.py Adds the Rust adapter/wrapper and validator factory.
openapi_spec_validator/schemas/init.py Switches schema validator proxies to use backend factories and exposes backend selection.
openapi_spec_validator/main.py Gates subschema detail printing based on backend support.
tests/integration/validation/test_exceptions.py Makes error-message assertions backend-agnostic (substring-based).
tests/integration/test_main.py Adjusts CLI-output assertions to handle backend differences and adds a backend-gating test.
tests/integration/test_shortcuts.py Adds tests for env-driven backend selection and module behavior.
tests/bench/runner.py Prints configured/effective backend in benchmark output.
docs/python.rst Documents backend selection env var.
docs/cli.rst Notes backend selection env var for CLI usage.
README.rst Documents backend selection env var in performance tuning section.
.github/workflows/python-tests.yml Runs test matrix for both jsonschema and jsonschema-rs backends.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@p1c2u
Copy link
Collaborator Author

p1c2u commented Mar 1, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Mar 1, 2026

@p1c2u I've opened a new pull request, #480, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 1, 2026 14:24
…, install docs, validate_formats

Co-authored-by: p1c2u <1679024+p1c2u@users.noreply.github.com>
Address jsonschema-rs backend review feedback
@p1c2u p1c2u merged commit 33585ea into master Mar 1, 2026
26 checks passed
@p1c2u p1c2u deleted the poc/rust-backend branch March 1, 2026 15:44
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.

3 participants