-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[move-stdlib] Introduce efficient OrderedMap implementation #14872
Conversation
⏱️ 4h 33m total CI duration on this PR
🚨 2 jobs on the last run were significantly faster/slower than expected
|
aptos-move/framework/aptos-stdlib/sources/data_structures/ordered_map.move
Show resolved
Hide resolved
aptos-move/framework/aptos-stdlib/sources/data_structures/ordered_map.move
Show resolved
Hide resolved
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## igor/native_compare #14872 +/- ##
====================================================
Coverage 57.4% 57.4%
====================================================
Files 859 859
Lines 211663 211663
====================================================
Hits 121527 121527
Misses 90136 90136 ☔ View full report in Codecov by Sentry. |
aptos-move/framework/aptos-stdlib/sources/data_structures/ordered_map.move
Show resolved
Hide resolved
aptos-move/framework/aptos-stdlib/sources/data_structures/ordered_map.move
Show resolved
Hide resolved
aptos-move/framework/aptos-stdlib/sources/data_structures/ordered_map.move
Show resolved
Hide resolved
return; | ||
}; | ||
|
||
// TODO: can be implemented more efficiently, as we know both maps are already sorted. |
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.
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.
yeah, but issue is here we have vectors, not lists, and so how to do it in-place, without moving too many elements.
Easiest is to can either create a new vector, populate, and then swap (I'll probably just do that)
if "vector" here had capacity, I could start from the end, without temporary storage, but I don't have a way to create empty values here (i.e. have this work without value being drop+copy)
f(iter.iter_borrow_key(self), iter.iter_borrow(self)); | ||
iter = iter.iter_next(self); | ||
} | ||
// vector::for_each_ref( |
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.
what's wrong here?
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.
entry is not a public type, so when this get's inlined in the caller, it cannot do compile.
basically inline functions need to be implemented only using public API.
I can remove this snippet as well
|
||
// return index containing the key, or insert position. | ||
// I.e. index of first element that has key larger or equal to the passed `key` argument. | ||
fun binary_search<K, V>(key: &K, entries: &vector<Entry<K, V>>, start: u64, end: u64): u64 { |
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 make a standard Entry
and implement binary search only once?
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 am writing binary search only once.
If you mean for binary search to be reusable, so other's don't need to write it, maybe that should be an inline function in vector
Moving Entry to a standard separate file, makes all field accesses to require getter and setter functions, not sure that's best
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.
amazing work! Thanks @igor-aptos . You are the hero!
b508022
to
18ba714
Compare
563d169
to
d58cde2
Compare
18ba714
to
b0d9226
Compare
d58cde2
to
70b3036
Compare
b0d9226
to
cef8611
Compare
70b3036
to
dc12951
Compare
cef8611
to
df51e9c
Compare
dc12951
to
c86d1c6
Compare
0b5371c
to
4fae0d1
Compare
4fae0d1
to
d24bb43
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d24bb43
to
6c389b5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6c389b5
to
f1dbc14
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f1dbc14
to
b60e336
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
Description
Implement efficient OrderedMap implementation in move-stdlib, to replace/deprecate SimpleMap. It is an in-memory datastructure - i.e. doesn't store anything in separate resources.
Implementation is a SortedVectorMap, but given the efficiency improvements of vector operations with memcpy, it's performance characteristics are extremely good.
Running different sizes tests (these are full results), we get milliseconds needed for 100 inserts and 100 removals on maps of different sizes:
Basically achieving log(n) performance, with very simple implementation.
How Has This Been Tested?
provided unit tests
Key Areas to Review
Type of Change
Which Components or Systems Does This Change Impact?
Checklist