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

Prefetch Improvement #2435

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion x/merkledb/db.go
Copy link
Contributor

@patrick-ogrady patrick-ogrady Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, this was shown to greatly improve concurrent prefetch performance (reads don't need to acquire the write lock on the cache like Put).

I'm wondering if it would make sense to include this optimization directly in the cache vs here or if this is considered non-standard usage/optimization? @StephenButtolph

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can directly include this into the cache because the cache would then need to somehow check if the provided value is equal. We could do that just directly with ==, but I feel like if we wanted to do that then we would want to make it more general.

Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,14 @@ func (db *merkleDB) PrefetchPath(key []byte) error {
func (db *merkleDB) prefetchPath(view *trieView, keyBytes []byte) error {
return view.visitPathToKey(ToKey(keyBytes), func(n *node) error {
if !n.hasValue() {
if _, ok := db.intermediateNodeDB.nodeCache.Get(n.key); ok {
dboehm-avalabs marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
return db.intermediateNodeDB.nodeCache.Put(n.key, n)
}

if _, ok := db.valueNodeDB.nodeCache.Get(n.key); ok {
return nil
}
db.valueNodeDB.nodeCache.Put(n.key, n)
return nil
})
Expand Down
Loading