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

Binary search offset cache #2368

Open
sideninja opened this issue Nov 4, 2024 · 1 comment
Open

Binary search offset cache #2368

sideninja opened this issue Nov 4, 2024 · 1 comment
Assignees

Comments

@sideninja
Copy link
Contributor

During attestation offset search, we are returning the consensus block height at which the offset was found, which can be then used in the next search as a starting height; we call this cursor.

During the offset search, even if the cursor was provided, we still do a binary forward search between cursor (or 0 on cold cache) and latest, which does a lot of iterations (average 30 from metrics). In cases where relayer is catching up the difference between cursor and latest can be big; this means a wide range will be searched with a binary search, but every time a binary search finds attestations with a higher offset, this knowledge can be reused in the next offset search.

One way to reuse this knowledge is to keep an in-memory cache of offsets found, which only get evicted from the cache once the cursor is bigger than the cached offset value. Having this kind of cache means we can exhaust it for follow-up searches.

Additionally the binary search is currently not effective because it's performed between cursor and latest by default, which can be improved by doing a forward exponential search to find bigger offset and then doing a binary search between those two values.

@sideninja
Copy link
Contributor Author

This issue will be re-evaluated after the relayer bootstrap is implemented, at that time we can gauge if the added complexity is worth it.

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

No branches or pull requests

1 participant