-
Notifications
You must be signed in to change notification settings - Fork 501
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
exp/orderbook: Speed up path finding by changing edgeSet data structure #3965
Conversation
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.
We never use edgeSet to do map lookups in the dfs.
I think I passively observed this during the latest changeset, but was too deep in a refactor to give it proper consideration. Super exciting to see a follow-up on it! 🎉
A few minor DRY-related comments and other questions below ⬇️
|
||
offers := e.values[i].offers | ||
updatedOffers := offers |
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.
Can we modify offers
directly?
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.
I didn't want to modify offers
while iterating through it in the for i, offer := range offers
loop
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.
Ah good point, I see. It won't keep iterating after it's modified since it break
s immediately, but I can see why you would do this to avoid confusion when reading the code.
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.
LGTM! I'm curious if you saw a boost after going for the []edge
approach?
|
||
offers := e.values[i].offers | ||
updatedOffers := offers |
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.
Ah good point, I see. It won't keep iterating after it's modified since it break
s immediately, but I can see why you would do this to avoid confusion when reading the code.
|
||
// addOffer will insert the given offer into the edge set | ||
func (e edgeSet) addOffer(key string, offer xdr.OfferEntry) { | ||
func (e edgeSet) addOffer(key string, offer xdr.OfferEntry) edgeSet { |
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.
Clever, great idea 👍
There wasn't a noticeable difference but the code was cleaner using an |
I did some profiling on path finding and found that iterating through entries in the edgeSet
map
was particularly expensive. We never useedgeSet
to do map lookups in the dfs. We only use the data structure to iterate through the key value pairs. So I changed the representation to a pair of lists and that resulted in a significant improvement in the path finding performance.Before applying the changes in this commit:
After applying the changes in this commit: