-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Replace array & linear lookup with map #3298
Comments
can I work on this issue?? |
Yes, @Aena11, it doesn't look like anybody else is making forward progress on this at the moment. Your contribution would be welcome. The links provided by @nbougalis are a little out of date. You would be changing this command map: to look something vaguely like this: Note that @nbougalis indicates that the change needs testing. Once the change is made we (you?) should time the new vs the old lookup times using a release build. If the |
@scottschurr, thanks for the reply I will start working on this |
|
@brianfranco141, this work has not been done and I've seen no evidence of pull requests aimed at addressing it. There's been no news on this from @Aena11 for 6 months as far as I'm aware. |
As this issue is open for a long time, I would like to work on it if currently, no one is working on it. |
Hello, I profiled the performance of the code with these four data structures: Linear Search on constexpr array: Binary Search on a constexpr sorted array: Std::map data structure: Std::unordered_map data structure: Since the performance of Many thanks to Scott Schurr for providing the profiling code and debugging, brainstorming this issue. [Observations as of July 2022] |
Detailed description: The below data structure (commands) is profiled with four alternatives - - linear search on an array - binary search on a sorted array - using std::map data structure - using std::unordered_map data structure. Both linear search and std::unordered_map outperformed the other alternatives. Hence, I don't think it warrants a change. If the number of rpc-handler-commands increase in the future, then there might be a scope for improvement. Detailed comparison - XRPLF#3298 (comment)
We profiled different algorithms and data structures to understand which strategy is best from a performance standpoint: - Linear search on an array; - Binary search on a sorted array; - Using `std::map`; and - Using `std::unordered_map`. Both linear search and std::unordered_map outperformed the other alternatives so no change to the existing data structure is justified. If more handers are added, this should be revisited. For some additional details and timings, please see: XRPLF#3298 (comment)
The RPC command handling code requires a thorough cleanup.
A good start would be to refactor the command map and the lookup code:
https://github.com/ripple/rippled/blob/develop/src/ripple/net/impl/RPCCall.cpp#L1154-L1249
Among the improvements, per the comment, the array chould be replaced with a
static const std::map<std::string_view, Command>
; at the same time thename
field should be removed fromCommand
.This may or not be faster. Testing to determine whether lookups are consistently faster using a hash table should be done, and if they indicate a performance gain, the change should be implemented. Otherwise, the comment should be removed.
The map initialization could be similar to this:
https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/TER.cpp#L35-L40
The text was updated successfully, but these errors were encountered: