Comments (6)
@pchampin Wow, this works extremely well, thanks for the great advice! None of the benchmarks have dropped at all and I support non-constant matchers now for all triple patterns. I have never used/seen monomorphization and didn't expect it to work when the respective functions are called inside other functions like filter.
from sophia_rs.
@KonradHoeffner now you are starting to get a feel for what "zero cost abstraction" really means :-)
from sophia_rs.
Most peobably, then HdtGraph
should be considered as not implementing Graph
trait. It can have it's custom methods to query with only Any
/ constant matchers.?
from sophia_rs.
That is a good point.
Originally I wanted to use the Sophia Graph trait in my application as a trait object, so that the code path is the same whether a user loads an RDF Turtle or an HDT file.
However in practice that is not possible anyways because the Sophia Graph trait cannot be used as a trait object, so there are different code paths anyways, so I will consider not implementing the Graph trait.
However there are still two problems:
- It would make sense to implement non-Any matches later, and still use optimized processing for the Any matcher.
- According to https://docs.rs/sophia/0.8.0-alpha.3/sophia/, in the latest version of Sophia the enum https://docs.rs/sophia/latest/sophia/term/matcher/enum.AnyOrExactly.html does not seem to exist anymore (I also checked out the repo and did not find it with
ack "AnyOrExactly",
I can build my own but reusing existing functionality would be more elegant).
from sophia_rs.
What I've done until now is just treat every matcher where tm.constant() returns None as Any
This is indeed a breach of the contract of the Graph
trait. Your argument for this is:
testing each entry would be too slow
Yes and no. Calling triples_matching
with, says, a closure as a matcher, would indeed be much slower than calling it with a constant matcher or Any
instead. But any call to triples_matching
with only constant matchers and Any
s would not be penalized, thanks to monomorphization (Any::matches
always return true, so it will be optimized away).
Granted, it would mean that calling triples_matching
would sometimes be very fast, and sometimes very slow, depending on the kind of matcher you pass. That might be considered a problem, but I would argue that it's the price to pay with any generic trait. You can still (and probably should) document, in your implementation, in which situations triples_matching
will perform well, and in which it won't.
You can even imagine providing an extra method, specific to your implementation, that you could call triples_matching_fast
for example, which would only accept the kind of parameters that make the call fast.
It could for example accept Option
s of terms, where Some(t)
would behave as a constant matcher, and None
would behave as Any
. All you would need to do would be to convert these parameters to the corresponding matcher, and call triples_matching
, which would be design be monomorphized to an efficient version.
from sophia_rs.
To summarize: you don't need to recognize the Any
matcher, because the compiler does that already during monomorphization, and does the "right thing" (i.e. optimizes away the call match
).
from sophia_rs.
Related Issues (20)
- Expose `JsonLdQuadSource` and `RdfTerm` types from `sophia_jsonld` HOT 1
- Documentation in the README HOT 1
- Add back query support HOT 4
- Issue casting string to literal with custom datatype using `*` HOT 2
- Issue serializing to TriG `with_pretty` when blank nodes HOT 2
- Parser failing on RDF/XML files with rdf:about="" HOT 2
- Please rework TermMatcher HOT 3
- Allow more optimizations with `TermMatcher` HOT 1
- Add configuration option to produce indented RDF/XML
- `bool` should implement `Term`
- `RcTerm::Triple` and `ArcTerm::Triple` do not live up to the "cheap clone" promise HOT 4
- Async parsers and serializers HOT 1
- Get rid of boxed iterators
- Add double-licensing (CeCILL-B + Apache V2) HOT 2
- Serialize isomorphic graphs to identical Turtle HOT 4
- Option to allow duplicated rdf:ID values HOT 1
- Add typos to code checking
- Add `Debug` supertype to `iri` parameter in `get` function of `Loader` trait HOT 3
- Iri<T> and IriRef<T> should implement Debug regardless of T
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sophia_rs.