Skip to content

Speed up validate() with validator caching and optional schema-check …#273

Merged
p1c2u merged 7 commits intomasterfrom
feature/shortcut-cache-and-check-schema-fastpath
Mar 1, 2026
Merged

Speed up validate() with validator caching and optional schema-check …#273
p1c2u merged 7 commits intomasterfrom
feature/shortcut-cache-and-check-schema-fastpath

Conversation

@p1c2u
Copy link
Collaborator

@p1c2u p1c2u commented Mar 1, 2026

…fast path

Large performance gain for repeated validate(...) calls on the same schema.

  • oas32_simple_object: 1162.84/s -> 53903.94/s (+4535.56%)
  • oas31_prefix_items: 852.47/s -> 41044.51/s (+4714.78%)
  • oas32_registry_refs: 1160.15/s -> 19221.49/s (+1556.81%)
  • oas30_nullable: 12597.89/s -> 175805.51/s (+1295.52%)
  • oas30_discriminator: 9615.88/s -> 18475.32/s (+92.13%)

@p1c2u p1c2u force-pushed the feature/shortcut-cache-and-check-schema-fastpath branch 4 times, most recently from c4f6c6b to 4eec6c2 Compare March 1, 2026 20:33
@p1c2u p1c2u force-pushed the feature/shortcut-cache-and-check-schema-fastpath branch from 4eec6c2 to 9227cca Compare March 1, 2026 20:36
@p1c2u p1c2u requested a review from Copilot March 1, 2026 20:36
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

This PR optimizes the validate(...) shortcut for repeated validations by caching compiled validators and adds a check_schema flag to optionally skip schema validation, along with benchmark tooling and documentation to measure/track performance.

Changes:

  • Add an internal LRU-style ValidatorCache for validate(...), plus clear_validate_cache() and check_schema support.
  • Introduce settings plumbing (env-driven cache size) and tests covering cache behavior and schema-check skipping.
  • Add benchmark runner/comparator scripts and document how to run them.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
openapi_schema_validator/shortcuts.py Implements validator caching, check_schema parameter, and cache clearing API.
openapi_schema_validator/_caches.py Adds thread-safe cache implementation and schema/kwargs keying.
openapi_schema_validator/settings.py Adds env-driven settings (OPENAPI_SCHEMA_VALIDATOR_VALIDATE_CACHE_MAX_SIZE) with caching/reset.
tests/unit/test_shortcut.py Adds tests for check_schema=False and cache behavior/max-size behavior.
benchmarks/run.py Adds benchmark runner to measure compile/validate throughput and memory.
benchmarks/compare.py Adds benchmark report comparison utility with regression detection.
benchmarks/cases.py Defines benchmark cases and shared schemas/registries.
benchmarks/__init__.py Initializes benchmark package.
docs/contributing.rst Documents benchmark usage and cache-size tuning.
pyproject.toml Adds settings dependencies (pydantic, pydantic-settings).
poetry.lock Locks new dependencies and updates dependency grouping metadata.

💡 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, #274, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits March 1, 2026 21:17
…port, GitHub Actions doc

Co-authored-by: p1c2u <1679024+p1c2u@users.noreply.github.com>
Fix review issues: ValidationError assertion, clear_validate_cache import, GitHub Actions docs
@p1c2u p1c2u merged commit f8ca4fc into master Mar 1, 2026
16 checks passed
@p1c2u p1c2u deleted the feature/shortcut-cache-and-check-schema-fastpath branch March 1, 2026 23:07
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