Skip to content

Commit 5510089

Browse files
authored
Improve build times for debug builds (simdjson#1859)
* Rename simdjson_really_inline -> simdjson_inline I want to change the simdjson_really_inline macro to sometimes not force inlining. After that upcoming change, the name simdjson_really_inline will no longer makes sense. Rename simdjson_really_inline to simdjson_inline. This patch should not change semantics; simdjson_inline still forces inlining as before. Some functions still need to be really inlined for ABI reasons. (GCC's -Wpsabi complains otherwise.) Leave those functions marked as simdjson_really_inline. * Improve build times for debug builds simdjson_inline is used for most simdjson functions. It forces inlining. In unoptimized/debug builds, this can lead to a lot of machine code being generated (especially with Address Sanitizer), causing slow compilation. Change simdjson_inline to force inlining only for optimized builds. Sometimes, the programmer might want a slightly-optimized build and want fast compilation (e.g. GCC's -Og mode). Allow simdjson users to define the simdjson_inline macro themselves (e.g. on the command line: -Dsimdjson_inline=inline) in cases where the default behavior is undesired. This patch reduced build times by over 75% for ondemand_object_tests.cpp with GCC 9.4.0 and CMAKE_BUILD_TYPE=Debug on my AMD 5950X: Before: 6.885 6.683 6.971 6.957 6.949 seconds (5 samples) After: 1.492 1.551 1.494 1.490 1.531 seconds (5 samples)
1 parent 62a5790 commit 5510089

140 files changed

Lines changed: 2554 additions & 2542 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎benchmark/amazon_cellphones/amazon_cellphones.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ using namespace json_benchmark;
1515
struct brand {
1616
double cumulative_rating;
1717
uint64_t reviews_count;
18-
simdjson_really_inline bool operator==(const brand &other) const {
18+
simdjson_inline bool operator==(const brand &other) const {
1919
return cumulative_rating == other.cumulative_rating &&
2020
reviews_count == other.reviews_count;
2121
}
22-
simdjson_really_inline bool operator!=(const brand &other) const { return !(*this == other); }
22+
simdjson_inline bool operator!=(const brand &other) const { return !(*this == other); }
2323
};
2424

2525
simdjson_unused static std::ostream &operator<<(std::ostream &o, const brand &b) {
@@ -66,8 +66,8 @@ struct runner : public file_runner<I> {
6666
template<bool threaded>
6767
struct simdjson_dom;
6868

69-
template<typename I> simdjson_really_inline static void amazon_cellphones(benchmark::State &state) {
69+
template<typename I> simdjson_inline static void amazon_cellphones(benchmark::State &state) {
7070
run_json_benchmark<runner<I>, runner<simdjson_dom<UNTHREADED>>>(state);
7171
}
7272

73-
} // namespace amazon_cellphones
73+
} // namespace amazon_cellphones

‎benchmark/benchfeatures.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct feature_benchmarker {
164164

165165
}
166166

167-
simdjson_really_inline void run_iterations(size_t iterations, bool stage1_only=false) {
167+
simdjson_inline void run_iterations(size_t iterations, bool stage1_only=false) {
168168
struct7.run_iterations(iterations, stage1_only);
169169
struct7_miss.run_iterations(iterations, stage1_only);
170170
struct7_full.run_iterations(iterations, stage1_only);

‎benchmark/benchmarker.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ struct benchmarker {
308308
return all_stages_without_allocation.iterations;
309309
}
310310

311-
simdjson_really_inline void run_iteration(bool stage1_only, bool hotbuffers=false) {
311+
simdjson_inline void run_iteration(bool stage1_only, bool hotbuffers=false) {
312312
// Allocate dom::parser
313313
collector.start();
314314
dom::parser parser;
@@ -384,7 +384,7 @@ struct benchmarker {
384384
loop << all_loop_count;
385385
}
386386

387-
simdjson_really_inline void run_iterations(size_t iterations, bool stage1_only, bool hotbuffers=false) {
387+
simdjson_inline void run_iterations(size_t iterations, bool stage1_only, bool hotbuffers=false) {
388388
for (size_t i = 0; i<iterations; i++) {
389389
run_iteration(stage1_only, hotbuffers);
390390
}

‎benchmark/distinct_user_id/distinct_user_id.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct runner : public file_runner<I> {
4646

4747
struct simdjson_dom;
4848

49-
template<typename I> simdjson_really_inline static void distinct_user_id(benchmark::State &state) {
49+
template<typename I> simdjson_inline static void distinct_user_id(benchmark::State &state) {
5050
run_json_benchmark<runner<I>, runner<simdjson_dom>>(state);
5151
}
5252

‎benchmark/distinct_user_id/sajson.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ struct sajson {
1111
size_t *ast_buffer{nullptr};
1212
~sajson() { free(ast_buffer); }
1313

14-
simdjson_really_inline std::string_view get_string_view(const ::sajson::value &obj, std::string_view key) {
14+
simdjson_inline std::string_view get_string_view(const ::sajson::value &obj, std::string_view key) {
1515
auto val = obj.get_value_of_key({key.data(), key.length()});
1616
if (val.get_type() != ::sajson::TYPE_STRING) { throw "field is not a string"; }
1717
return { val.as_cstring(), val.get_string_length() };
1818
}
19-
simdjson_really_inline uint64_t get_str_uint64(const ::sajson::value &obj, std::string_view key) {
19+
simdjson_inline uint64_t get_str_uint64(const ::sajson::value &obj, std::string_view key) {
2020
// Since sajson only supports 53-bit numbers, and IDs in twitter.json can be > 53 bits, we read the corresponding id_str and parse that.
2121
auto val = obj.get_value_of_key({key.data(), key.length()});
2222
if (val.get_type() != ::sajson::TYPE_STRING) { throw "field not a string"; }

‎benchmark/dom/statisticalmodel.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using stat_t = struct stat_s;
4141

4242

4343

44-
simdjson_really_inline void simdjson_process_atom(stat_t &s,
44+
simdjson_inline void simdjson_process_atom(stat_t &s,
4545
simdjson::dom::element element) {
4646
if (element.is<int64_t>()) {
4747
s.integer_count++;

‎benchmark/event_counter.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ struct event_collector {
156156
}
157157
#endif
158158

159-
simdjson_really_inline void start() {
159+
simdjson_inline void start() {
160160
#if defined(__linux)
161161
linux_events.start();
162162
#endif
163163
start_clock = steady_clock::now();
164164
}
165-
simdjson_really_inline event_count& end() {
165+
simdjson_inline event_count& end() {
166166
time_point<steady_clock> end_clock = steady_clock::now();
167167
#if defined(__linux)
168168
linux_events.end(count.event_counts);

‎benchmark/find_tweet/find_tweet.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct runner : public file_runner<I> {
3333

3434
struct simdjson_dom;
3535

36-
template<typename I> simdjson_really_inline static void find_tweet(benchmark::State &state) {
36+
template<typename I> simdjson_inline static void find_tweet(benchmark::State &state) {
3737
run_json_benchmark<runner<I>, runner<simdjson_dom>>(state);
3838
}
3939

‎benchmark/find_tweet/sajson.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ struct sajson {
1313
size_t *ast_buffer{nullptr};
1414
~sajson() { free(ast_buffer); }
1515

16-
simdjson_really_inline std::string_view get_string_view(const ::sajson::value &obj, std::string_view key) {
16+
simdjson_inline std::string_view get_string_view(const ::sajson::value &obj, std::string_view key) {
1717
auto val = obj.get_value_of_key({key.data(), key.length()});
1818
if (val.get_type() != ::sajson::TYPE_STRING) { throw "field is not a string"; }
1919
return { val.as_cstring(), val.get_string_length() };
2020
}
21-
simdjson_really_inline uint64_t get_str_uint64(const ::sajson::value &obj, std::string_view key) {
21+
simdjson_inline uint64_t get_str_uint64(const ::sajson::value &obj, std::string_view key) {
2222
// Since sajson only supports 53-bit numbers, and IDs in twitter.json can be > 53 bits, we read the corresponding id_str and parse that.
2323
auto val = obj.get_value_of_key({key.data(), key.length()});
2424
if (val.get_type() != ::sajson::TYPE_STRING) { throw "field not a string"; }

‎benchmark/json2msgpack/json2msgpack.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ template <typename I> struct runner : public file_runner<I> {
4141
struct simdjson_ondemand;
4242

4343
template <typename I>
44-
simdjson_really_inline static void json2msgpack(benchmark::State &state) {
44+
simdjson_inline static void json2msgpack(benchmark::State &state) {
4545
run_json_benchmark<runner<I>, runner<simdjson_ondemand>>(state);
4646
}
4747

48-
} // namespace json2msgpack
48+
} // namespace json2msgpack

0 commit comments

Comments
 (0)