-
Notifications
You must be signed in to change notification settings - Fork 39
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
TPF indexing in Db #14
Comments
Resources have an explicit parent. Getting the parent is a cheap operation, but generating the children is expensive, as it currently requires a TPF query that iterates over all items. This specific operation should be very quick, but I'd like to make the optimizations generalizable. One way to optimize this TPF query, is to keep track of incoming links. We could create a new inverted tree for this: So when we have this |
While I was working on the document editor, performance for Collections became pretty bad. This was due to the Documents creating a lot of Commits and Elements, and there was no indexing in the DB. When a Collection was to be fetched, a TPF query would be done, which in turn iterated over every resource... So I've started to build a value index. The Value index seems to be working properly, and it solves the performance issues I've had locally. But a new issue is arising: it takes way to long to build the index. On my dev machine, where I have some 500MB of things in the store, it took about 30 minutes to build the index. It's insane. Every resource takes about 100+ ms. But why? I have no clue. Maybe it's time to add some serious benchmarking. |
Cause for slow indexing
... which respectively result in extremely big For every atom, the DB needs to read out and write these very big objects. The Some objects are over 1 MB. Which means reading and writing 1 MB for some atoms.
Value-property indexInstead of having a But... A ValueProperty index for Store commits in a separate indexSince about 90% of the time on indexing on my local machine was for the commits, we might be able to skip these, or treat them differently. Would probably mean that some queries would no longer work for commits. Maybe the commit collection will need to change, in order to achieve this. Post way less resourcesThis problem only arises if we have... lots of resources. Which we might not need. NestedResources for Documents might be the best place to start. Use a different approach to (de-)serializing sled data.If I understand correctly, rkyv allows for mutating resources without deserializing and reserializing the binary. I think this could be a significant part of the slowdown. Make it a background processIf building an index is slow, that might not be a really big problem, as long as it happens in the background.... We could spin up an actix thread on server initialization, which iterates over all resources. Or maybe introduce an |
I'm pretty content with the current implementation. Closing for now. |
Although TPF queries are implemented, they are very slow and won't scale - a single TPF query iterates over all individual atoms in the store. To solve this, we need some type of index. Since we're using Sled, a key-value store, we can't use some SQL index, we need to build it ourselves.
One solution is to create two new Sled tree (a new k-v store). In the first one (for searching by Value) every k represents an Atomic Value, and v a vector of all subjects. In the second one for Properties, k = property, v = subject.
However, a very common TPF query will be like this:
* isA SomeClass
. If we only do above indexes, this will still be a costly query, because we'll still iterate over many resources - pretty much all resources will have theisA
property.We could improve performance if we'd also store the Property in the
v
fields mentioned above, instead of only storing the subjects. To prevent unnecessary data duplication / minimize storage impact, it might make sense to not store entire atoms, but to leave out the thing that's already known (the thing in the key).A TPF query such as
* isA SomeClass
would probably start with using the ValueIndex, which return all SubjectProperty combinations. Then, the implementation will iterate over all SubjectProperties, filtering by property, returning all subjects.I think Atomic Collections will rely on this query quite a bit: make a list of all Persons (or some class), sorted by some thing. This will do such a TPF query using the indexes, than returns all subjects.
Another possible optimization strategy is caching Collections (which internally use TPF queries). We could rebuild (or invalidate) them on Commits.
The text was updated successfully, but these errors were encountered: