Repository navigation
key_selector: compile with clang and -fno-exceptions - #2913
Merged
Merged
Conversation
The compile-time perfect-hash construction reported failures with `throw "..."` inside consteval functions. Clang rejects any throw expression when exceptions are disabled, even one that is only evaluated at compile time, so simdjson.h no longer compiled under C++20 with -fno-exceptions (as used by Node.js and Chromium). GCC accepts it, which is why it went unnoticed. Report the failures by calling a non-constexpr function instead: it is still a compile-time error, with a diagnostic pointing at the message, and it needs no exception support. Also compile the tests with -fno-exceptions when SIMDJSON_EXCEPTIONS is OFF. Until now, only GCC got the flag, and only on the library's link line, so the "noexcept" CI jobs never compiled the headers without exceptions.
nodejs-github-bot
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 11, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
nodejs-github-bot
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 11, 2026
env.h includes inspector_profiler.h, which included simdjson.h for the types of two virtual methods and a parser member. As a result, about 155 files in src/ parsed the amalgamated simdjson header, which is over 10 MB. Keep simdjson out of inspector_profiler.h: the profile connections now say which field of `result` holds the profile, and WriteProfile() takes the profile as raw JSON. The parser becomes a local variable, so its buffers are no longer kept alive for the lifetime of the Environment. Also drop the unused include from node_task_runner.h, and let the config file reader rewind its document instead of parsing the whole file a second time with a second parser. Now only the eight files that use simdjson include it. On an Apple M-series machine, a clean rebuild of the src/ objects takes about 15% less CPU time (376 s to 320 s) and 19% less wall time at -j14. Signed-off-by: Daniel Lemire <[email protected]> PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
env.h includes inspector_profiler.h, which included simdjson.h for the types of two virtual methods and a parser member. As a result, about 155 files in src/ parsed the amalgamated simdjson header, which is over 10 MB. Keep simdjson out of inspector_profiler.h: the profile connections now say which field of `result` holds the profile, and WriteProfile() takes the profile as raw JSON. The parser becomes a local variable, so its buffers are no longer kept alive for the lifetime of the Environment. Also drop the unused include from node_task_runner.h, and let the config file reader rewind its document instead of parsing the whole file a second time with a second parser. Now only the eight files that use simdjson include it. On an Apple M-series machine, a clean rebuild of the src/ objects takes about 15% less CPU time (376 s to 320 s) and 19% less wall time at -j14. Signed-off-by: Daniel Lemire <[email protected]> PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
env.h includes inspector_profiler.h, which included simdjson.h for the types of two virtual methods and a parser member. As a result, about 155 files in src/ parsed the amalgamated simdjson header, which is over 10 MB. Keep simdjson out of inspector_profiler.h: the profile connections now say which field of `result` holds the profile, and WriteProfile() takes the profile as raw JSON. The parser becomes a local variable, so its buffers are no longer kept alive for the lifetime of the Environment. Also drop the unused include from node_task_runner.h, and let the config file reader rewind its document instead of parsing the whole file a second time with a second parser. Now only the eight files that use simdjson include it. On an Apple M-series machine, a clean rebuild of the src/ objects takes about 15% less CPU time (376 s to 320 s) and 19% less wall time at -j14. Signed-off-by: Daniel Lemire <[email protected]> PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
richardlau
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 12, 2026
env.h includes inspector_profiler.h, which included simdjson.h for the types of two virtual methods and a parser member. As a result, about 155 files in src/ parsed the amalgamated simdjson header, which is over 10 MB. Keep simdjson out of inspector_profiler.h: the profile connections now say which field of `result` holds the profile, and WriteProfile() takes the profile as raw JSON. The parser becomes a local variable, so its buffers are no longer kept alive for the lifetime of the Environment. Also drop the unused include from node_task_runner.h, and let the config file reader rewind its document instead of parsing the whole file a second time with a second parser. Now only the eight files that use simdjson include it. On an Apple M-series machine, a clean rebuild of the src/ objects takes about 15% less CPU time (376 s to 320 s) and 19% less wall time at -j14. Signed-off-by: Daniel Lemire <[email protected]> PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
aduh95
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 23, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
aduh95
pushed a commit
to nodejs/node
that referenced
this pull request
Oct 28, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
aduh95
pushed a commit
to nodejs/node
that referenced
this pull request
Nov 11, 2026
PR-URL: #66620 Refs: simdjson/simdjson#2913 Refs: #66495 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Richard Lau <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
simdjson 5.0.2 does not compile with clang in C++20 mode when exceptions are disabled (
-fno-exceptions), which is how Node.js and Chromium build:The compile-time perfect-hash construction in
key_selector.hreports failures withthrow "..."insideconstevalfunctions. Clang rejects any throw expression when exceptions are disabled, even one that is only evaluated at compile time. GCC accepts it.Changes
key_selector.h: report the failures by calling a non-constexpr function instead of throwing. Reaching it during constant evaluation is still a compile-time error, and the diagnostic shows the call with its message (e.g. duplicate keys infor_each<"a", "a">still fail to compile, with or without exceptions).cmake/developer-options.cmake: compile the tests with-fno-exceptionswhenSIMDJSON_EXCEPTIONS=OFF.Why CI did not catch it
In
cmake/exception-flags.cmake,-fno-exceptionsis only added whenCMAKE_COMPILER_IS_GNUCC, only throughtarget_link_libraries, and only to the library target. So the "CXX 20, noexcept" jobs (g++-13 and clang++-16) never compiled the headers without exceptions. With the CMake change alone,ondemand_object_find_field_testsfails to build on master with the error above.I did not make the library itself build with
-fno-exceptions: with libc++,std::string::__throw_length_errorthen callsabort(), which breaks theavoid_aborttest.Testing
AppleClang,
-DSIMDJSON_CXX_STANDARD=20 -DSIMDJSON_EXCEPTIONS=OFF -DSIMDJSON_DEVELOPER_MODE=ON: everything builds, 109/109 tests pass. Node.jsmainalso builds with simdjson 5.0.2 plus this patch.