Closed pderaaij closed 1 month ago
This is amazing @pderaaij ! I am back from holidays (you know, italy + august = holiday) so will look a bit more into the PR this week
Sharing some high level thoughts here.
As I was doing some research in the approach, I came across the trie
data structure, which fundamentally feels like what we are kinda implementing here.
As I looked into it, I realized that using the reversed path (similar to what we do in getShortestIdentifier
) and saving in in a trie would be the cleanest solution, as it would out of the box replace the existing indexing while giving us the features and performance we want.
What do you think? Again, this was at a cursory look, I might be missing something
Never really looked into the trie datastructure. Will do some research and fiddle around!
I need a bit more time to figure out the right approach. Have been looking into tie data structures, but most implementation I found are immutable. A characteristic we don't want for our use case here. So, I need to find an implementation that does allow mutations. Did a quick checkout of https://rimbu.org, but couldn't find a right data structure off the bat for our use case. So, I require some more time to look around and find a solution. Ideas welcome of course.
I got a long way tonight using https://yomguithereal.github.io/mnemonist/trie-map. Need to finish some things and get the last use cases working. Will do a new performance test when things are working. Hopefully I can finish it later this week.
@riccardoferretti I've updated the implementation with my WIP so far.
It has a little impact on performance. Compared to the earlier version, I now load the 10000s
workspace in 2 to 3 seconds. Which still is a massive improvement compared to the current implementation. I do feel the performance impact is acceptable given the ease of maintenance this implementation brings in the code.
I have one remaining issue and I hope you can help. Originally, a Map holds the insertion order. TrieMap obviously does not do that. But, this means that resources()
needs to return a sorted Iterator. I can't find a correct way to sort the values and then return an IteratableIterator
. Perhaps you have an idea here?
If we can resolve this issue, all tests will be green so we can do some further testing and enhancing before shipping it.
@riccardoferretti it seems I was on the right track, but simply not sharp after a long day of work. Got it working now. Please review and check accordingly.
@riccardoferretti somehow I managed to break the build in CI. Locally all works, but can't get it going on Actions. Could you have a look?
@pderaaij I think it's related to the markdown-it version change
Yeah, I was hoping that would fix it. Had the problems after rebasing the lock files. Which was a hassle on its own....
Well... I found the little bugger:
I am giving up on this PR. Going to do a fresh branch on master and open a new PR. Not trusting all the mess this has created.
Based on some performance findings found #1375 I started to experiment with some improvements. I've noticed the function
listByIdentifier
being called alot by other functions. In this function, there is aforeach
loop running over all resources. A function which works fine for small notebooks, but large notebooks seems to be hit exponentionally.In this concept I've added a new state object that lists all resources for an identifier. In this case, I choose the identifier to be the file-name of the note. Using that identifier, I list all resource paths with that same identifier. Using this I can remove the
foreach
loop and just use the identifier to list a small set of resources.For the 10000 linked notes folder from this repo (https://github.com/rcvd/interconnected-markdown/tree/main/Markdown) this reduces the startup time to:
Using the current master the numbers are:
A delta of almost 25 seconds for loading the graph. Not only a performance improvement for loading the workspace, but also for some other operations that uses
listByIdentifier
directly or viafind
. This should make several UI components work better and more responsive.The downside is that it adds a new stateful object, but I don't see an other way to increase the performance of the foreach loop.
@riccardoferretti curious to your thoughts on this.