Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 16 min read Deep dive hardMaster

CPU Dispatch in ClickHouse

CPU dispatch lets a single binary use SIMD instruction sets like AVX2 and AVX-512 while staying compatible with older CPUs: hot functions are compiled for several targets with the target attribute, and the best variant is chosen at runtime using CPUID feature checks. The walkthrough covers auto-vectorization basics with clang, including __restrict for aliasing, vzeroupper, and -Rpass remarks for diagnosing missed vectorization, plus a fix that moves a member-variable accumulator into a local. It also describes how ClickHouse structures its dispatch framework with a TargetArch enum and instruction-set-specific code blocks. Practical advice for finding candidates is to build with different instruction sets or compiler options and compare performance tests.

Assumes: C++x86 assembly basicsSIMD conceptscompiler optimization flags

Related posts

  • How ClickHouse Cloud uses AWS Graviton to boost performance and efficiency

    ClickHouse mediumAdept

    ClickHouse Cloud moved about 83% of its AWS fleet from x86 instances (M5/R5) to Graviton ARM instances, building on AArch64 support work that began in 2016 and grew to cover Neon optimizations, JIT and profiling. Because compute and storage are separated, no data had to move. The main engineering work was replacing Intel-only codecs (deflate_qpl, zstd_qat) and making autoscaling work with mixed m7gd/m6gd instance types. That meant matching memory allocations, routing pods under 236Gi to ARM via a webhook, and overprovisioning to handle "architecture jumps." Benchmarks showed about 25% overall query improvement, only 10% on a network-bound S3 workload, and up to 64% for Graviton4 (r8g) versus Intel on ClickBench.

  • Running ClickHouse on NVIDIA Vera CPU: Is your favorite database up to the challenge?

    ClickHouse mediumAdept

    ClickHouse, run unmodified on NVIDIA's early-access Vera CPU (2×88 Arm Olympus cores, 352 SMT threads, ~1.2 TB/s memory bandwidth), topped the ClickBench hardware leaderboard. Micro-benchmarks on a 1 TB in-memory table show near-linear scaling for CPU-bound filters, low-cardinality aggregation and parallel hash joins up to the 176 physical cores, with efficiency dropping beyond that as SMT threads give only modest gains. A simple LIKE filter becomes memory-bound at ~64 threads (~813–900 GB/s). Disabling auto-vectorization on a comparison loop made a single-threaded filter 3.5x slower, showing the value of NEON SIMD, with SVE2 support in progress.

  • Platform-independent SIMD in Go

    The Go Blog hardMaster

    Go 1.27 adds an experimental, size-agnostic `simd` package, loosely modeled on Highway for C++. It hides differences in vector width, masking schemes and instruction sets across AVX/AVX2/AVX512, NEON and wasm, and falls back to emulation on platforms without SIMD support. Vector types such as `simd.Float32s` have no fixed length; they load from and store to slices and expose only operations in the cross-platform intersection, with gaps filled by emulation. When an operation is missing, code can drop into the architecture-specific `archsimd` package via `ToArch()`/`FromArch`, and the compiler specializes away the type switch, as shown with a lookup-table popcount implementation for AVX/AVX2.

  • ClickHouse Cloud on Google Cloud Now Powered by Google Axion Processors: 30–55% Faster Queries, ~15% Fewer Compute Credits

    ClickHouse easyNovice

    ClickHouse Cloud is migrating its Google Cloud fleet from x86 N2D instances to Arm-based Axion C4A instances, yielding 30–55% faster queries across all 43 ClickBench queries, roughly halved load times, and first place on the combined ClickBench ranking. Across a controlled cohort of 38 production services, compute credits per query fell about 15%, with larger gains for CPU-bound workloads and smaller ones where GCS read throughput dominates. The rollout went from staging to region-by-region migration, gated on SharedCatalog storage, maintenance windows and traffic tier, with the highest-traffic organizations moved last. Contributing factors cited include steadier clock frequency under sustained load and one physical core per vCPU instead of two hyperthreads.

  • Arch-specific SIMD in Go

    The Go Blog hardMaster

    Go 1.27 extends the experimental architecture-specific SIMD API (simd/archsimd, enabled with GOEXPERIMENT=simd) from amd64 to arm64 NEON and wasm 128-bit SIMD. The design uses typed vector structs, readable method names unified across architectures, opaque mask types that the compiler peepholes into masked instructions, and new zero-cost reinterpretation methods (ToBits, ReshapeToUint<W>s) that replace Go 1.26's As<Type> methods. Worked examples reverse bits with GFNI affine transforms and transpose an 8x8 matrix with AVX2 lane-grouped permutes. Practical advice: guard code with CPU feature checks, which avoid SIGILL and also enable fused AVX-512 lowering; write loop bounds as i < len-n+1 so bounds checks are eliminated; and pass vectors as separate values rather than arrays or structs so they stay in registers.

The quest for software engineering knowledge.

Look:
Layout: