Skip to content

[Feature]: Improve performance by using a faster library for parsing json schemas #1086

Open

Description

@mikicz

Suggested Behavior

Use fastjsonschema instead of jsonschema, or even jsonschema-rs. jsonschema-rs claims to be 30x to 390x faster than jsonschema (3x to 7x faster than fastjsonschema).

Why is this needed?

I have an OpenAPI spec that's moderately big, roughly 1.6M and parsing it with OpenAPI takes about 15s on my computer. I unfortunately can't share it, but I can share the profiling on it.

For one-time use it would be fine, but we use it in tests to validate responses, so this adds quite a bit of runtime to tests.

References

This profiling of just loading the OpenAPI yaml file, using OpenAPI.from_file_path("<path>")

The part in blue is jsonschema.

Image

A bit more detail here: x.txt

Would you like to implement a feature?

None

Activity

  1. p1c2u commented on Jan 30, 2026

    @p1c2u
    Collaborator

    Hi @mikicz , thanks for your comment. I see in your profiling that your bottleneck is specification validation on the OpenAPI initialization. You can turn off the validation if you are sure your specification is valid. Please read the documentation how to disable spec validation.

    If your intention is it use specification validation feature but make it faster then that would require changes in openapi-spec-validator and openapi-schema-validator which are entirely based on jsonschema.

  2. p1c2u commented on Feb 1, 2026

    @p1c2u
    Collaborator

    After little bit more investigation and profiling I found out the issue with suboptimal reference resolution in jsonschema-path library. The fix should have more impact than switching to jsonschema-rs.

    p1c2u/jsonschema-path#208

  3. p1c2u commented on Feb 17, 2026

    @p1c2u
    Collaborator

    Betea version with performance improvements was released. Feel free to test it.

  4. mikicz commented on Feb 17, 2026

    @mikicz
    Author

    Hi! Thanks for still looking at this! I have indeed found that just disabling spec validation does help quite a bit. Nonetheless I have tried to profile the current release and the pre-release with our spec file.

    With validation:

    from openapi_core import OpenAPI
    
    if __name__ == "__main__":
        OpenAPI.from_file_path("schema.yaml")

    Without validation:

    from openapi_core import OpenAPI, Config
    
    if __name__ == "__main__":
        config = Config(spec_validator_cls=None)
        OpenAPI.from_file_path("schema.yaml", config=config)

    Old dependencies:

    $ uv pip freeze | grep 'openapi\|jsonschema\|pathable'
    fastjsonschema==2.21.2
    jsonschema==4.26.0
    jsonschema-path==0.3.4
    jsonschema-specifications==2025.9.1
    openapi-core==0.22.0
    openapi-schema-validator==0.6.3
    openapi-spec-validator==0.7.2
    pathable==0.4.4
    

    New dependencies:

    $ uv pip freeze | grep 'openapi\|jsonschema\|pathable'
    fastjsonschema==2.21.2
    jsonschema==4.24.1
    jsonschema-path==0.4.0b8
    jsonschema-specifications==2025.9.1
    openapi-core==0.23.0b1
    openapi-schema-validator==0.6.3
    openapi-spec-validator==0.8.0b3
    pathable==0.5.0b6
    

    The headline is that I do not see any major time improvement - tho I can imagine my setup being less than ideal - I only ran once per variant instead of running multiple times. See pyinstrument profiling:

    old.txt
    new.txt
    new_without_validation.txt
    old_without_validation.txt

  5. p1c2u commented on Feb 17, 2026

    @p1c2u
    Collaborator

    Thanks for sharing your results. The improvement should only be visible when the spec validation is enabled.

    I’ve prepared a PoC for the jsonschema-rs version. It’s definitely worth moving forward, but it requires more time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions