Skip to content

Commit 1fd40af

Browse files
committed
Slight perf benefit from using swiss tables
absl::flat_hash_{set,map} are called "swiss tables", and they provide a small perf win for us.
1 parent 116b12b commit 1fd40af

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

extras/analyze/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.20.3)
33
project(EventAnalyze)
44

55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
67

78
include(FetchContent)
89

@@ -20,6 +21,14 @@ FetchContent_Declare(
2021
)
2122
FetchContent_MakeAvailable(pybind11)
2223

24+
FetchContent_Declare(
25+
abseil
26+
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
27+
GIT_TAG f39e6ad4753e06d4a0d6a9bf6310478757479984
28+
)
29+
set(BUILD_TESTING OFF)
30+
FetchContent_MakeAvailable(abseil)
31+
2332
FetchContent_Declare(
2433
FindTBB
2534
GIT_REPOSITORY https://github.com/justusc/FindTBB.git
@@ -45,4 +54,4 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "src/*.cpp")
4554
pybind11_add_module(eventanalyze ${sources})
4655
target_include_directories(eventanalyze PUBLIC include)
4756
target_compile_features(eventanalyze PUBLIC cxx_std_20)
48-
target_link_libraries(eventanalyze PRIVATE mio::mio)
57+
target_link_libraries(eventanalyze PRIVATE mio::mio absl::base absl::flat_hash_map)

extras/analyze/include/types.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "py.hpp"
1616

17+
#include <absl/container/flat_hash_map.h>
18+
#include <absl/container/flat_hash_set.h>
1719
#include <mio/mmap.hpp>
1820

1921
namespace ev {
@@ -91,7 +93,7 @@ struct EventIdEq {
9193
};
9294

9395
using BlockEventMap =
94-
std::unordered_set<std::vector<Event>, EventIdHash, EventIdEq>;
96+
absl::flat_hash_set<std::vector<Event>, EventIdHash, EventIdEq>;
9597

9698
struct Logs;
9799
struct Benchmark;

extras/analyze/src/parse.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <ranges>
1111
#include <string>
1212
#include <string_view>
13-
#include <unordered_map>
14-
#include <unordered_set>
1513
#include <utility>
1614
#include <vector>
1715

@@ -65,9 +63,9 @@ static EventSchema parseEventSchema(
6563
// Schemas are globally loaded.
6664
// This static/thread_local dance is to make it appropriately thread safe but
6765
// still fast.
68-
static std::unordered_set<EventSchema, EventIdHash, EventIdEq> MasterSchemas;
66+
static absl::flat_hash_set<EventSchema, EventIdHash, EventIdEq> MasterSchemas;
6967
static std::mutex MasterSchemaMutex;
70-
thread_local std::unordered_set<EventSchema, EventIdHash, EventIdEq> Schemas;
68+
thread_local absl::flat_hash_set<EventSchema, EventIdHash, EventIdEq> Schemas;
7169

7270
static void updateSchemaStructures(EventId Id, EventSchema schema) {
7371
std::scoped_lock Lock(MasterSchemaMutex);
@@ -167,7 +165,7 @@ static const std::boyer_moore_horspool_searcher
167165
EventTagSearcher(EventTag.begin(), EventTag.end());
168166

169167
static BlockEventMap parseEvents(const std::string_view BlockLog) {
170-
std::unordered_map<EventId, std::vector<Event>, EventIdHash, EventIdEq>
168+
absl::flat_hash_map<EventId, std::vector<Event>, EventIdHash, EventIdEq>
171169
Result;
172170

173171
const auto E = BlockLog.end();
@@ -205,7 +203,9 @@ static Block parseBlock(ev::Benchmark *Bench, const std::string_view BlockLog) {
205203
.RawLog = BlockLog,
206204
.UniqueId = std::move(UniqueId),
207205
.Bench = Bench,
208-
.File = "", // TODO: Get this information too
206+
// Extracting file info costs quite a bit of time, and we never use it
207+
// anyway.
208+
.File = "",
209209
};
210210
}
211211

0 commit comments

Comments
 (0)