-
Notifications
You must be signed in to change notification settings - Fork 34
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
Computation of document order needs to be cached #121
Comments
It was also pointed out that we can have a "short cut" if the nodeset only has a single node. In that case, the computation of document order can be avoided entirely. |
Using the short cut does fix this case 👍
I also cleaned up the original code a bit: let root = radlex.root();
let mut ctx = Context::new();
ctx.set_namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
let factory = Factory::new();
let xpath = factory.build("/rdf:RDF/*/@rdf:ID[starts-with(., 'RID')]")?;
let xpath = xpath.expect("No XPath was compiled");
let value = xpath.evaluate(&ctx, root)?;
if let Value::Nodeset(nodeset) = value {
let dict = nodeset
.into_iter()
.filter_map(|node| node.attribute())
.map(|a| (a.value().into(), a.parent().unwrap()))
.collect();
Ok(dict)
} else {
panic!()
} |
What's painful about caching in the full case is that there's nowhere really good to store the cache. The closest place right now would be something like the The best alternative within the current structure I can think of would be some ugly hidden thing inside of a |
A pragmatic compromise could be to have a pair of functions, such as |
This program causes intense performance usage. Ultimately, it's because
Value::into_string
is being called repeatedly, which triggers the computation of nodes in document order. "Thankfully", I realized this problem when adding it:sxd-xpath/src/nodeset.rs
Line 349 in 350c51e
Source file
/cc @Enet4
The text was updated successfully, but these errors were encountered: