-
Notifications
You must be signed in to change notification settings - Fork 0
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
Panic when trying to validate STAC schema #2
Comments
Blocked by Stranger6667/jsonschema#306 |
Hmmm... After I redesigned the api and did the benchmark, ajv is recommended to use instead of this lib. |
As a possible solution to this overhead problem, I think we can take a look at this issue. If the input will implement the Another point is that the compilation phase takes quite a lot on the What do you think? |
In the new version, I compile to a JSONSchema first , then call
How could you let the JsObject in v8 to implement Json trait in rust? |
The trick is commonly known as a New Type idiom. It exists for sake of compile-time guarantees and is compiled away in the final artifacts. struct JsObjectWrapper(JsObject);
impl jsonschema::Json for JsObjectWrapper {
// Here goes the access to internals, etc.
}
fn validate(input: JsObject) -> bool {
let compiled = ...;
compiled.is_valid(JsObjectWrapper(input))
} In the bindings code, you'll need to wrap the input The design of the |
Though I'll take a deeper look into the existing implementation and I am very curious to check some profiling results as well. So we can be sure where do we have a bottleneck. |
Here are methods of JsObject, https://docs.rs/napi/1.7.7/napi/struct.JsObject.html#method.coerce_to_string. |
As far as I see, |
FYI, changing that block gives only 2x speedup :( #[js_function(1)]
fn compile(ctx: CallContext) -> Result<JsFunction> {
let arg0 = ctx.get::<JsString>(0)?.into_utf8()?;
let schema = from_str(arg0.as_str()?)?;
let compiled = JSONSchema::options()
.with_draft(Draft::Draft7)
.compile(&schema)
.map_err(|e| Error::new(Status::InvalidArg, format!("{}", e)))?;
ctx.env.create_function_from_closure("isValid", move |ctx| {
let arg = ctx.get::<JsUnknown>(0)?;
let input = ctx.env.from_js_value(arg)?;
ctx.env.get_boolean(compiled.is_valid(&input))
})
} |
But, I don't think that UPDATE: Missed it - it accepts the original input |
The only solution for this kind of bottleneck is using napi methods as little as possible, which is conflict with jsonschema validating scene as node-addon... |
Using
@node-rs/jsonschema@^0.1.2"
I receive a rust panic when trying to validate documents against https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json
The text was updated successfully, but these errors were encountered: