From 9aaa0dff5fd422e5f6880df8e20a1fd5ad3b4424 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Fri, 15 Jul 2022 16:26:48 -0700 Subject: [PATCH] Build the command map at compile time (fixes #3298): 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: https://github.com/XRPLF/rippled/issues/3298#issuecomment-1185946010 --- src/ripple/net/impl/RPCCall.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 334ca8693..eb4906f3a 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -1227,10 +1227,7 @@ public: int maxParams; }; - // FIXME: replace this with a function-static std::map and the lookup - // code with std::map::find when the problem with magic statics on - // Visual Studio is fixed. - static Command const commands[] = { + static constexpr Command commands[] = { // Request-response methods // - Returns an error, or the request. // - To modify the method, provide a new method in the request.