Improve build times for debug builds (#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)
This commit is contained in:
strager
2022-07-19 12:14:33 -07:00
committed by GitHub
parent 62a57907a7
commit 5510089d45
140 changed files with 2533 additions and 2521 deletions
+7 -7
View File
@@ -13,7 +13,7 @@ namespace stage1 {
class structural_scanner {
public:
simdjson_really_inline structural_scanner(dom_parser_implementation &_parser, stage1_mode _partial)
simdjson_inline structural_scanner(dom_parser_implementation &_parser, stage1_mode _partial)
: buf{_parser.buf},
next_structural_index{_parser.structural_indexes.get()},
parser{_parser},
@@ -21,16 +21,16 @@ simdjson_really_inline structural_scanner(dom_parser_implementation &_parser, st
partial{_partial} {
}
simdjson_really_inline void add_structural() {
simdjson_inline void add_structural() {
*next_structural_index = idx;
next_structural_index++;
}
simdjson_really_inline bool is_continuation(uint8_t c) {
simdjson_inline bool is_continuation(uint8_t c) {
return (c & 0xc0) == 0x80;
}
simdjson_really_inline void validate_utf8_character() {
simdjson_inline void validate_utf8_character() {
// Continuation
if (simdjson_unlikely((buf[idx] & 0x40) == 0)) {
// extra continuation
@@ -92,7 +92,7 @@ simdjson_really_inline void validate_utf8_character() {
}
// Returns true if the string is unclosed.
simdjson_really_inline bool validate_string() {
simdjson_inline bool validate_string() {
idx++; // skip first quote
while (idx < len && buf[idx] != '"') {
if (buf[idx] == '\\') {
@@ -108,7 +108,7 @@ simdjson_really_inline bool validate_string() {
return false;
}
simdjson_really_inline bool is_whitespace_or_operator(uint8_t c) {
simdjson_inline bool is_whitespace_or_operator(uint8_t c) {
switch (c) {
case '{': case '}': case '[': case ']': case ',': case ':':
case ' ': case '\r': case '\n': case '\t':
@@ -121,7 +121,7 @@ simdjson_really_inline bool is_whitespace_or_operator(uint8_t c) {
//
// Parse the entire input in STEP_SIZE-byte chunks.
//
simdjson_really_inline error_code scan() {
simdjson_inline error_code scan() {
bool unclosed_string = false;
for (;idx<len;idx++) {
switch (buf[idx]) {