Principle:ClickHouse ClickHouse Core Compiler Macros
| Knowledge Sources | |
|---|---|
| Domains | Build_System, Portability |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Essential preprocessor definitions that abstract compiler-specific features and platform differences.
Description
Core compiler macros provide portable abstractions over compiler-specific features like branch prediction hints (likely/unlikely), inlining directives, platform detection, and annotations. They enable writing code that compiles across different compilers and platforms while taking advantage of compiler-specific optimizations when available. ClickHouse uses these extensively for performance (branch hints), correctness (assertions), and thread safety (TSA annotations).
Usage
Use when writing portable code that needs compiler-specific optimizations, implementing assertion systems, or adding thread safety annotations.
Theoretical Basis
Branch Prediction: `__builtin_expect` hints to compiler which branch is likely, improving instruction cache usage.
Link-Time Optimization: Inlining hints (ALWAYS_INLINE, NO_INLINE) guide LTO decisions.
Thread Safety Analysis: Clang's TSA uses annotations to verify lock usage at compile time.
Platform Detection: Macros like `__x86_64__` enable conditional compilation for platform-specific code.