Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ref keyword caches built validators #83

Conversation

macisamuele
Copy link
Contributor

The goal of this PR is to reduce validation penalty performance while interacting with $refs.

At the current state every time we're trying to validate such object we're actually re-building all the validators (which is essentially the compile part of the process).

I've tried to move validators build logic (currently in RefValidator::ensure_validators) into the compilation process, but it get's though due to potential circular dependencies with references.
In order to reduce the code changes and keep performances in consideration I'm opting for storing the validators behind a RwLock.
The decision of using it is mostly related to the fact that respect a Mutex it does have similar performances but at the same time allows multiple readers (in our case multiple parallel validations).

Performance improvements are over well 45% improvement for validation. Raw data in here

PS. once again this was spotted while working on maci-split-validators 😎

@macisamuele macisamuele force-pushed the maci-ref-keyword-caches-built-validators branch from 5c37bb1 to 91156bc Compare May 23, 2020 13:17
Copy link
Owner

@Stranger6667 Stranger6667 left a comment

Choose a reason for hiding this comment

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

A minor typo :) Otherwise it is a great improvement! Great to see it

src/keywords/ref_.rs Outdated Show resolved Hide resolved
src/keywords/ref_.rs Outdated Show resolved Hide resolved
src/keywords/ref_.rs Show resolved Hide resolved
@Stranger6667
Copy link
Owner

-95.816%

Just wow :)

@macisamuele
Copy link
Contributor Author

To be honest, in realistic cases (where references point to big schemas) I would expect even bigger improvements.
Think about Swagger specifications where the reference points to the schema of an endpoint response (ie. interacting with Kubernetes)

@macisamuele macisamuele force-pushed the maci-ref-keyword-caches-built-validators branch from 91156bc to d6cc224 Compare May 23, 2020 13:36
@Stranger6667 Stranger6667 merged commit b309ab5 into Stranger6667:master May 23, 2020
@macisamuele macisamuele deleted the maci-ref-keyword-caches-built-validators branch May 23, 2020 13:52
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.

None yet

2 participants