-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Conversation
…push and relying on the fact these validators always compile without errors
… and relying on the fact this compile function always return Some
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
It generates a simpler assembly
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 |
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.$ref
and boolean validators are compiled without callingpush
on a vector, i.e. the vector is created more efficientlyIt gives ~9.6% speedup for boolean validators and really small speedup for
$ref
(probably need a better benchmark). There is a visible improvement in theperf
output.to_string
call during format validators compilationIt gives ~11% improvement
compile
calls with#[inline]
On validators that don't involve regex compilation, it gave from 3 to 25% improvement
DEFAULT_SCOPE
inresolve_fragment
Not really about compilation, but it is 25-30% of improvement during reference resolving on various benches
FormatValidator
with generated structsImproves 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 extramatch
, which seems to be slightly faster than a function call overhead. I'll cleanup duplication later