Skip to content
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

use bipf seekKeyCached() #325

Closed
wants to merge 1 commit into from
Closed

use bipf seekKeyCached() #325

wants to merge 1 commit into from

Conversation

staltz
Copy link
Member

@staltz staltz commented Apr 4, 2022

Context: ssbc/jitdb#208

Uses BIPF 1.6.0's seekKeyCached API instead of passing pValue around.

Pending on ssbc/jitdb#209 being merged first.

@staltz
Copy link
Member Author

staltz commented Apr 4, 2022

@arj03 Here's the ssb-db2 PR that combines everything. I didn't have time to run benchmarks today, but wanted to make this available for you already.

@arj03
Copy link
Member

arj03 commented Apr 4, 2022

I ran the benchmarks and it seems as if caching is not kicking in for some reason. Havn't delved deep into the code to see why:

Only JITDB query:
master: 10.1s
this branch: 15.5s

Both JITDB + level indexes during query:
master: 37.4
this branch: 47.3

@staltz
Copy link
Member Author

staltz commented Apr 4, 2022

You might need a full npm install, so I mean rm -rf node_modules

@arj03
Copy link
Member

arj03 commented Apr 4, 2022

Still the same. Even tried deleting package-lock before running npm i.

@staltz
Copy link
Member Author

staltz commented Apr 4, 2022

Hmmm, it might just be that this new code is slower 🥲

@arj03
Copy link
Member

arj03 commented Apr 4, 2022

Well at least we have a good new baseline :) I can see that it is definitely hitting to cache inside bipf, so not exactly sure what is going on.

@staltz
Copy link
Member Author

staltz commented Apr 6, 2022

I ran benchmarks on my side as well, and can confirm that the new code would be slower. See before/after.

See also the heatmap from Chrome. 1.5s just spent on cache.get / cache.set is way too much:

Screenshot from 2022-04-06 12-53-49

I think the root cause, if I can guess, is that there is too many new Map() going on, since the structure of the cache is WeakMap -> Map -> Map -> number. I don't know how to do this differently, because we can't just use [buffer, start, target] array as the key to the Map, because arrays aren't unique.

I figured that's it's worth documenting why this approach didn't work. But I'll close the PRs. 🥲

Before

query: 39678.767ms
query: 44708.553ms
query: 42647.140ms

After

query: 47966.423ms
query: 47688.483ms
query: 48343.490ms

@staltz staltz closed this Apr 6, 2022
@staltz staltz deleted the bipf-cached branch April 6, 2022 09:59
@arj03
Copy link
Member

arj03 commented Apr 6, 2022

Yeah, good benchmarks. The multiple dictionaries would also have been my guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants