Skip to content

Commit ef7ef1a

Browse files
committed
THashMap -> absl::flat_hash_map (+9% performance on benchmark)
1 parent 20c847c commit ef7ef1a

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

ydb/library/binary_json/ut_benchmark/write.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ NJson::TJsonValue GetTestJson(ui64 depth = 10, ui64 nChildren = 2) {
3232

3333
TString GetTestJsonString() {
3434
seed = 42;
35-
return NJson::WriteJson(GetTestJson(2, 100));
35+
return NJson::WriteJson(GetTestJson(3, 50));
3636
}
3737

3838
static void BenchWriteSimdJson(benchmark::State& state) {
@@ -47,4 +47,4 @@ static void BenchWriteSimdJson(benchmark::State& state) {
4747

4848
}
4949

50-
BENCHMARK(BenchWriteSimdJson);
50+
BENCHMARK(BenchWriteSimdJson)->MinTime(1);

ydb/library/binary_json/write.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#include <contrib/libs/simdjson/include/simdjson/dom/object-inl.h>
77
#include <contrib/libs/simdjson/include/simdjson/dom/parser-inl.h>
88
#include <contrib/libs/simdjson/include/simdjson/ondemand.h>
9+
#include <library/cpp/containers/absl_flat_hash/flat_hash_map.h>
910
#include <library/cpp/json/json_reader.h>
10-
11-
#include <util/generic/vector.h>
12-
#include <util/generic/stack.h>
13-
#include <util/generic/set.h>
1411
#include <util/generic/algorithm.h>
1512
#include <util/generic/map.h>
13+
#include <util/generic/set.h>
14+
#include <util/generic/stack.h>
15+
#include <util/generic/vector.h>
1616

1717
#include <cmath>
1818

@@ -77,7 +77,7 @@ struct TContainer {
7777
* container index instead. This is exactly how containers are stored in serialized BinaryJson (but with offsets instead of indices)
7878
*/
7979
struct TJsonIndex {
80-
ui32 InternKey(const TStringBuf value) {
80+
ui32 InternKey(const TStringBuf& value) {
8181
TotalKeysCount++;
8282

8383
const auto [it, emplaced] = Keys.emplace(value, LastFreeStringIndex);
@@ -88,7 +88,7 @@ struct TJsonIndex {
8888
return it->second;
8989
}
9090

91-
ui32 InternString(const TStringBuf value) {
91+
ui32 InternString(const TStringBuf& value) {
9292
const auto [it, emplaced] = Strings.emplace(value, LastFreeStringIndex);
9393
if (emplaced) {
9494
++LastFreeStringIndex;
@@ -130,15 +130,15 @@ struct TJsonIndex {
130130
TStack<ui32> ContainerIndex;
131131
TVector<TContainer> Containers;
132132

133-
TMap<TString, ui32> Keys;
133+
TMap<std::string, ui32> Keys;
134134
ui32 TotalKeyLength = 0;
135135
ui32 TotalKeysCount = 0;
136136

137-
THashMap<TString, ui32> Strings;
137+
absl::flat_hash_map<std::string, ui32> Strings;
138138
ui32 LastFreeStringIndex = 0;
139139
ui32 TotalStringLength = 0;
140140

141-
THashMap<double, ui32> Numbers;
141+
absl::flat_hash_map<double, ui32> Numbers;
142142
ui32 LastFreeNumberIndex = 0;
143143

144144
ui32 TotalEntriesCount = 0;

ydb/library/binary_json/ya.make

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ YQL_ABI_VERSION(
77
)
88

99
PEERDIR(
10+
library/cpp/containers/absl_flat_hash
1011
library/cpp/json
11-
ydb/library/conclusion
12+
ydb/library/conclusion
1213
ydb/library/yql/minikql/dom
1314
contrib/libs/simdjson
1415
)

0 commit comments

Comments
 (0)