Skip to content

[build] Define ISA extensions for all 1st party code#6093

Merged
fhanau merged 1 commit intomainfrom
felix/021726-build
Feb 19, 2026
Merged

[build] Define ISA extensions for all 1st party code#6093
fhanau merged 1 commit intomainfrom
felix/021726-build

Conversation

@fhanau
Copy link
Copy Markdown
Contributor

@fhanau fhanau commented Feb 17, 2026

Notes for reviewers:

@fhanau fhanau requested review from mikea and npaun February 17, 2026 19:35
@fhanau fhanau requested review from a team as code owners February 17, 2026 19:35
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 17, 2026

Merging this PR will not alter performance

✅ 70 untouched benchmarks
⏩ 129 skipped benchmarks1


Comparing felix/021726-build (f447aa2) with main (fcf3784)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@fhanau
Copy link
Copy Markdown
Contributor Author

fhanau commented Feb 17, 2026

Looks like clang-tidy is getting errors with an intrinsics header when parsing src/workerd/tests/bench-tools.h 🙄
This is happening since we are using clang-tidy-21 while still using LLVM19 otherwise and LLVM19 headers try to use an MMX builtin that has been removed in LLVM 21. This seems like too small of a nuisance to justify updating to (and requiring) LLVM21, I'll just disable header parsing for that target and add a comment for now.

Copy link
Copy Markdown
Contributor

@dom96 dom96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This should fix #5977 by ensuring both places where we compute SQL-related hashes use hardware acceleration.

Should/can we add a test for this?

@fhanau
Copy link
Copy Markdown
Contributor Author

fhanau commented Feb 18, 2026

LGTM

This should fix #5977 by ensuring both places where we compute SQL-related hashes use hardware acceleration.

Should/can we add a test for this?

We should – @FlorentCollin said that he could write a test for this, the only wrinkle is that it will merely cause a "HashIndex detected hash table inconsistency" warning if there was a regression. In the future, we should have some way to have errors in tests cause an exception instead of just a log, for doing this in capnproto we might add a KJ_DASSERT (that way it would not just affect tests but be limited to debug builds and thus not affect release builds, hopefully good enough).

- Ideally we'd enable this on all C/C++ code, but that's difficult (see TODO
  comment)
- This should fix #5977 by ensuring both places where we
  compute SQL-related hashes use hardware acceleration. To address this more
  generally, we'll need to make changes in capnp (capnproto/capnproto#2564)
- Also fixes a regression where crc-impl.c++ was compiled without CRC extensions
  enabled, which appears to have caused the software-based CRC32C implementation
  to be used
- Define -O3 properly for perfetto-tracing target on Windows, for consistency
@fhanau fhanau force-pushed the felix/021726-build branch from d4701f8 to f447aa2 Compare February 19, 2026 18:35
@fhanau fhanau merged commit fafdac0 into main Feb 19, 2026
22 checks passed
@fhanau fhanau deleted the felix/021726-build branch February 19, 2026 20:39
@kentonv
Copy link
Copy Markdown
Member

kentonv commented Feb 23, 2026

Can't we set global copt via .bazelrc?

Does this change cover the capnp dependency? I think it's important that it be compiled with consistent flags since hash codes could be passed between workerd code and capnp code.

@fhanau
Copy link
Copy Markdown
Contributor Author

fhanau commented Feb 23, 2026

Can't we set global copt via .bazelrc?

Does this change cover the capnp dependency? I think it's important that it be compiled with consistent flags since hash codes could be passed between workerd code and capnp code.

Unfortunately, we can't do that in a way that works in all edge cases – .bazelrc gives us no way to determine the cpu architecture, so unless we require the user to pass flags like --config=x64 or --config=arm64 we can't enable something for all targets (we could set that in CI, but expecting users to pass that flag or add it to their ~/.bazelrc seems onerous). One way to enforce this is using a custom Bazel C++ toolchain (as we do internally), where we can easily set flags based on the architecture, but that would mean adding a lot more configuration here. Maybe @mikea has some other ideas

This does not include capnproto – that's why I would prefer to always use the same hash function and fall back to using a software implementation, while having mixed compile flags is not ideal it is something that commonly happens when using precompiled libraries that do not enable ISA extensions beyond the x64 baseline (e.g. in apt packages). We'd want to avoid it, but capnproto should be able to handle it gracefully.

@kentonv
Copy link
Copy Markdown
Member

kentonv commented Feb 26, 2026

We need to figure out how to compile all of workerd -- including capnproto -- with the same flags.

Mixing implementations between translation units is not the right answer, even if they are designed to be equivalent. It's fragile and it's an ODR violation.

If we need to just force these flags on in the capnp bazel build, that's better than what we have now.

@fhanau
Copy link
Copy Markdown
Contributor Author

fhanau commented Feb 27, 2026

We need to figure out how to compile all of workerd -- including capnproto -- with the same flags.

Mixing implementations between translation units is not the right answer, even if they are designed to be equivalent. It's fragile and it's an ODR violation.

If we need to just force these flags on in the capnp bazel build, that's better than what we have now.

We can enable the required flags for all capnproto code by introducing a kj_cc_library macro and using that instead of plain cc_library, similarly to what we do with wd_cc_library in workerd. By using a flag, we can also make it possible to opt out if desired.
That would just cover capnproto (and not all of workerd), but we can also add a poisoning mechanism based on preprocessor defines so that compilation will fail if code that depends on KJ is being compiled with the Bazel flag on but without having the hardware extensions enabled. Does that work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 BUG: Import an D1 exported DB cannot be imported in local - HashIndex detected hash table inconsistency

5 participants