Recently in the performance tuning for the recommended service, the main logic of this service is to use the offline computing model data for each ad in the request to score, and then return the order of these ads, the process of scoring in fact with the data in the request to spell a variety of keys, to check a large map, this calculation is very much, Become the main performance bottleneck, the code is older, using the Boost::unordered_map, in order to solve this problem, find some third-party libraries and standard library compared a bit
Here are ther4.xlargetest results on an AWS machine (note that you must add-o2 when compiling):
std::map<int, int> => 51866903
std::unordered_map<int, int> => 3838175
std::unordered_map<int, int, nohashint> => 3508570
std::unordered_map<int, int>(N) => 3804471
boost::unordered_map<int, int> => 3291384
boost::unordered_map<int, int, nohashint> => 3293934
boost::unordered_map<int, int>(N) => 3265856
google::dense_hash_map<int, int> => 785969
google::dense_hash_map<int, int, nohashint> => 784455
google::dense_hash_map<int, int>(N) => 899262
tsl::hopscotch_map<int, int> => 654668
tsl::hopscotch_map<int, int, nohashint> => 680964
tsl::hopscotch_map<int, int>(N) => 663607
tsl::robin_map<int, int> => 406176
tsl::robin_map<int, int, nohashint> => 411358
tsl::robin_map<int, int>(N) => 409993
Can see Tsl::robin_map performance basically can reach Std::unordered_map 10 times times, this performance and the operating system and the library version also has a certain relationship, the actual production environment is recommended to pull down the code in their own environment test
We used Tsl::robin_map to replace the original BOOST::UNORDERED_MAP, the overall performance increased 5 times times, which also contains some other optimizations, this optimization is a relatively large optimization point