-
Notifications
You must be signed in to change notification settings - Fork 1.4k
balances fwd fill asof test #9171
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
base: main
Are you sure you want to change the base?
Conversation
asof join test results summarytest descriptions
initial run (full refresh)
winner: test3 — consistently 5-35% faster than original on full refresh. incremental run
winner: test3 — fastest or tied on incremental runs. conclusions
recommendation: test3 is the optimal asof implementation. it replaces only the |
follow up question: |
yep, it's to compare 2 big chains (arbitrum + base) vs 2 small ones (linea + scroll) just few more notes:
hints welcome 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomfutago I had a quick look, can you add another approach that uses just 1 asof join like this:
High level this should look like this:
with balance_updates as (
select * from balances_source
where address_filter
and token_filter
and incremental_filter
),
asof_subjects as (
select distinct
address, token_address
from balance_updates
),
asof_spine as (
select
timestamp
,address
,token_address
from asof_subjects
cross join (select timestamp from utils.day where <incremental window>)
),
select
timestamp
,address
,token_address
,balance
from asof_spine
asof join balance_updates
on address = address
and token_address = token_address
and timestamp <= balance_updated_at
There's also an issue that you're not accounting for balance updates that occured before the start of the incremental window (and carrying those into the current window), but I would keep that as a follow up. I have some examples on how to do that as well somewhere.
|
thanks @0xRobin i might be missing something but your suggested approach looks like my test1, is it not? |
|
ah yes you are right! @tomfutago I think all approaches are missing the historical lookback for incremental updates though, can you add that as well. I wonder if for approach 1 it would be better to do it in 2 stages, one to construct the cross join spine and the final one to asof join with the balance updates. |
|
updated - test3 version still seems to winning: initial run (full refresh)
winner: test3 - up to 2.5× faster on smaller chains, consistent improvement across all. incremental run
winner: test3 - slight edge on incremental, test1 also competitive now. |
Thank you for contributing to Spellbook 🪄
Please open the PR in draft and mark as ready when you want to request a review.
Description:
[...]
quick links for more information: