Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:ClickHouse ClickHouse Core Compiler Macros

From Leeroopedia


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.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment