-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
Use a better structure instead of Map
in validators
#91
Comments
Map
in validatorsMap
in validators
The first tests showed a significant improvement in compilation but a slowdown in validation. But with FNV hasher it seems faster. Maybe we can avoid |
Hm, for a small number of properties a simple |
@Stranger6667 I would be curious to get to know more how you're actually deriving these conclusions (out of genuine interest). |
Side note: checking the code specifically I see that we do only access to enum StringSet {
None,
Single(String),
Small(Vec<String>), // up to 8 values (assuming that micro benching confirms this threshold)
Large(HashSet<String>),
} |
Sure! Some time ago I tried flame graphs to get a breakdown of what is being executed in the binary. My usual workflow:
use jsonschema::JSONSchema;
use serde_json::json;
fn main() {
let schema = json!(...);
let instance = json!(...);
let compiled = JSONSchema::compile(&schema, None).unwrap();
for _ in 0..10000000 {
compiled.is_valid(&instance);
}
}
[profile.release]
debug = true
Then there will be
And #!/usr/bin/sed -rf
# Unmangle Rust symbols
# See https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?id=cae15db74999edb96dd9f5bbd4d55849391dd92b
# Example, with [FlameGraph](https://github.com/brendangregg/FlameGraph):
# perf record -g target/debug/bin
# perf script | stackcollapse-perf | rust-unmangle | flamegraph > perf.svg
# Remove hash and address offset
s/::h[0-9a-f]{16}//g
s/\+0x[0-9a-f]+//g
# Convert special characters
s/\$C\$/,/g
s/\$SP\$/@/g
s/\$BP\$/*/g
s/\$RF\$/\&/g
s/\$LT\$/</g
s/\$GT\$/>/g
s/\$LP\$/(/g
s/\$RP\$/)/g
s/\$u20\$/ /g
s/\$u27\$/'/g
s/\$u5b\$/[/g
s/\$u5d\$/]/g
s/\$u7b\$/{/g
s/\$u7d\$/}/g
s/\$u7e\$/~/g
# Fix . and _
s/\.\./::/g
s/[^\.]\.[^\.]/./g
s/([;:])_/\1/g
And there is a nice representation which is easy to navigate. Basically from that, I found that significant time is spent in
I will do it
I want to say that I appreciate your work very much!
Yep, it might work! But wouldn't it be more efficient to use a generic here to avoid one indirection level? Not sure how to do it, but if our validator can accept anything that does |
@Stranger6667 FYI There is a
I'm considering to create a PR where I add a new directory ( |
Thank you for bringing this! Unfortunately, those SVGs were not working properly on my machine (they were not interactive), so I found an alternative. I'll take a deeper look, most probably it is some local misconfiguration / missing package issue |
That's sad ... I hope that you identify a simple tool ;) |
E.g. in
AdditionalPropertiesNotEmptyValidator
. Because during the validation we useself.properties.contains_key(*property)
which will be O(logN) (because of BTreeMap). We can useHashMap
to have O(1).As
perf
showed, significant time is spent on itThe text was updated successfully, but these errors were encountered: