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

Improve compilation performance #62

Merged
merged 12 commits into from
May 20, 2020
Merged

Conversation

Stranger6667
Copy link
Owner

@Stranger6667 Stranger6667 commented May 19, 2020

  1. Avoid string allocation during scope parsing & do not re-parse DEFAULT_ROOT_URL

Before, the string was cloned anyway - either DEFAULT_ROOT_URL or the one from the schema and then passed to Url::parse where it was cloned again.

Benches:
boolean_false compile false: -72% (212.48 ns -> 59.542 ns)
jsonschema big schema compile: -7.1% (3.4517 us -> 3.2085 us)
jsonschema small schema compile: -5.6% (3.3137 us -> 3.1238 us)

This behavior is reproducible over other benchmarks. It will have the most effect on the (re)compilation of small schemas + frequent use jsonschema::is_valid without reusing compiled schema.

  1. $ref and boolean validators are compiled without calling push on a vector, i.e. the vector is created more efficiently

It gives ~9.6% speedup for boolean validators and really small speedup for $ref (probably need a better benchmark). There is a visible improvement in the perf output.

  1. Avoid to_string call during format validators compilation

It gives ~11% improvement

  1. Mark all compile calls with #[inline]

On validators that don't involve regex compilation, it gave from 3 to 25% improvement

  1. Reusing DEFAULT_SCOPE in resolve_fragment

Not really about compilation, but it is 25-30% of improvement during reference resolving on various benches

  1. Replacing FormatValidator with generated structs

Improves compilation for this keyword by 7-8% and makes validation slightly faster (probably due to removing a func call overhead). But for validate there is an extra match, which seems to be slightly faster than a function call overhead. I'll cleanup duplication later

@codecov
Copy link

codecov bot commented May 19, 2020

Codecov Report

Merging #62 into master will decrease coverage by 0.71%.
The diff coverage is 85.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #62      +/-   ##
==========================================
- Coverage   84.44%   83.72%   -0.72%     
==========================================
  Files          45       45              
  Lines        3143     3176      +33     
==========================================
+ Hits         2654     2659       +5     
- Misses        489      517      +28     
Impacted Files Coverage Δ
src/keywords/additional_items.rs 95.16% <ø> (ø)
src/keywords/additional_properties.rs 86.29% <ø> (ø)
src/keywords/boolean.rs 81.48% <ø> (-18.52%) ⬇️
src/keywords/const_.rs 100.00% <ø> (ø)
src/keywords/contains.rs 96.55% <ø> (ø)
src/keywords/enum_.rs 95.83% <ø> (ø)
src/keywords/exclusive_maximum.rs 96.15% <ø> (ø)
src/keywords/exclusive_minimum.rs 96.15% <ø> (ø)
src/keywords/if_.rs 93.18% <ø> (ø)
src/keywords/items.rs 88.46% <ø> (ø)
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b57fa7...99f19aa. Read the comment docs.

@Stranger6667
Copy link
Owner Author

So, for some more or less realistic schemas, this PR gives 8-12% improvement in the compilation time and from 40% to 80% improvement for small single-keyword schemas

@Stranger6667 Stranger6667 marked this pull request as ready for review May 20, 2020 13:10
@Stranger6667 Stranger6667 merged commit 0fc9eb6 into master May 20, 2020
@Stranger6667 Stranger6667 deleted the dd/improve-compilation branch May 20, 2020 13:10
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.

1 participant