-
Notifications
You must be signed in to change notification settings - Fork 110
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
refactor: use ordered publisher list #402
Conversation
5335952
to
8b2f52f
Compare
8b2f52f
to
4fa26a9
Compare
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 don't love the incremental sorting pass -- see inline comment -- but happy to discuss that if there's some particular reason you are doing it this way
0e81986
to
58afc9d
Compare
6a58b0a
to
13aeaef
Compare
This change brings down the average cost of a price update without aggregation from 5k to 2k because binary search requires much less lookups. There are mechanims implemented in the code to make sure that upon the upgrade we sort the array without adding overhead to the happy path (working binary search). Also add_publisher now does an insertion sort to keep the list sorted and del_publisher won't change the order of the list.
13aeaef
to
c27465d
Compare
{ | ||
price_data.comp_.swap(current_index, current_index - 1); | ||
current_index -= 1; | ||
} |
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.
minor comment: imo, we should call sort_price_comps
here as well, because the insertion code above isn't tested by the quickcheck stuff below. We don't add publishers a lot so we don't care about optimizing CU use.
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.
(feel free to ignore this. I'm only saying it because it feels like the maximally defensive implementation)
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.
did that. removed the inline
hint to make sure code size doesn't get larger (by sacrificing a bit of CU)
45002cf
to
37e99b8
Compare
46cda78
to
b991cba
Compare
This change brings down the average cost of a price update without aggregation from 5k to 2k by moving from unordered list of publishers to an ordered list of publishers on doing binary search on lookup. It will fall back to linear search if the binary search fails.
Also add_publisher now tries to sort the list with [0,0,0...] (Base58: 11111...) publisher as a migration path. The sort is implemented in a way to be efficient and small (in code size). There is an insertion sort upon each new publisher to make sure the list remains sorted. del_publisher won't change the order of the list so it will remain sorted.
The heavy code path for publishers now uses
sol_memcmp
(on sorting and lookup) to be more optimized (it costs 10 CU and apparently publisher equality is a few times more expensive). I checked sol_memcmp without change to sorted but the result was not as significant. Maybe later we can extract it out to a function, and use it everywhere.