rules/sdk: flag methods inside sort comparators to avoid quadratic worst case time & memory consumption: instead recommend O(n) computations and memoization of results #43
Labels
enhancement
New feature or request
Summary
If we look at this cosmos-sdk issue cosmos/cosmos-sdk#7766 we can see that it was fixed by cosmos/cosmos-sdk#8719 and one of the root causes was this code
of which sdk.AccAddressFromBech32 is an expensive function that discards prior work inside the quicksort routine which in the worst case is
O(n^2)
and if we have 100K accounts, that could be(100K * 100K)
= 10 million times and if for example each call takes a couple of milliseconds that code can take ages to run and that was the root causeRecommendation
Our recommendation for that is to recommend that they create a slice whose elements are a struct with the memoized value for the comparator inside an O(n) slice along with the original value, then a sort and then in-place copying thus
The text was updated successfully, but these errors were encountered: