-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore(events): improve perf for parallel event filter matching #12603
base: master
Are you sure you want to change the base?
Conversation
@rvagg : is this something you're hoping to see land for 1.31.0? |
Yes, but I'd like chainindexer to land first, this can go in separately. Like #12623 I think they deserve separate call-outs in the CHANGELOG. |
35a9852
to
e01d209
Compare
@rvagg should we land this now, given that we are looking at release v1.31.0-rc1 tomorrow? |
1. Cache address look-ups for the given tipset across filters 2. Run the filters in an errgroup
e01d209
to
db90330
Compare
Tagging @masih who would be a good person to review this change. |
@@ -28,7 +29,10 @@ func isIndexedValue(b uint8) bool { | |||
return b&(types.EventFlagIndexedKey|types.EventFlagIndexedValue) > 0 | |||
} | |||
|
|||
type AddressResolver func(context.Context, abi.ActorID, *types.TipSet) (address.Address, bool) | |||
// AddressResolver is a function that resolves an actor ID to an address. If the | |||
// actor ID cannot be resolved to an address, the function should return |
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.
// actor ID cannot be resolved to an address, the function should return | |
// actor ID cannot be resolved to an address, the function must return |
...because the code correctness depends on it?
if err := f.CollectEvents(ctx, tse, false, m.AddressResolver); err != nil { | ||
return err | ||
} | ||
f := f |
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.
Redundant now that this module depends on Go 1.22.
f := f |
if err := f.CollectEvents(ctx, tse, true, m.AddressResolver); err != nil { | ||
return err | ||
} | ||
f := f |
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.
Ditto.
} | ||
|
||
return nil | ||
} | ||
|
||
func (m *EventFilterManager) createTipSetCachedAddressResolver() func(ctx context.Context, emitter abi.ActorID, ts *types.TipSet) address.Address { |
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.
Subjective:
- This could be a function (in FP sense): takes an address resolver and returns a cached version of it.
Then:
- One could wrap the struct field resolver with it at EventFilterManager.
- This would avoid multiple calls to
createTipSetCachedAddressResolver
in favour of singular cached address resolver for the lifetime of event filter manager (assuming this is desirable for performance reasons, though watch out for unbounded map size growth).
Blocked until #12421 is merged and we can do this against master.
I started writing up a
good-first-issue
ticket for this but it eneded up being easier to write the code than describe what needed doing.bool
return argument and just useaddress.Undef
, I believe there's no case where this is an acceptable valueFilters can be installed via
eth_newFilter
,eth_subscribe
andSubscribeActorEventsRaw
. All filters installed haveCollectEvents
run on them for each new tipset and revert. So this can get expensive if you're an RPC provider who allows users to install these things and watch for live events.