---
title: "CPU Dispatch in ClickHouse"
description: "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."
url: "https://swe.quest/articles/cpu-dispatch-in-clickhouse-5bbf7a6eb81cd552"
canonical: "https://clickhouse.com/blog/cpu-dispatch-in-clickhouse"
source: "ClickHouse"
published: "2023-10-03"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 16
tags: ["c-cpp","performance","compilers","hardware","analytics"]
---

# CPU Dispatch in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-10-03, 16 min read, Deep dive. Original: [https://clickhouse.com/blog/cpu-dispatch-in-clickhouse](https://clickhouse.com/blog/cpu-dispatch-in-clickhouse)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- C++ ([easy posts on C & C++](https://swe.quest/tags/c-cpp.md?difficulty=easy))
- x86 assembly basics
- SIMD concepts
- compiler optimization flags ([easy posts on Performance engineering](https://swe.quest/tags/performance.md?difficulty=easy))

## Keywords

ClickHouse, AVX2, AVX-512, SSE4.2, CPUID, clang, auto-vectorization

## Related posts

- [How ClickHouse Cloud uses AWS Graviton to boost performance and efficiency](https://swe.quest/articles/how-clickhouse-cloud-uses-aws-graviton-to-boost-performance-and-efficiency-52a991e3221f8e14.md): ClickHouse · 2025-01-27 · Medium · 6 min read · Hardware, Cloud platforms, Performance engineering, Analytics & OLAP, Kubernetes
  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.
- [Running ClickHouse on NVIDIA Vera CPU: Is your favorite database up to the challenge?](https://swe.quest/articles/running-clickhouse-on-nvidia-vera-cpu-is-your-favorite-database-up-to-the-2e92c798f70f3113.md): ClickHouse · 2026-10-21 · Medium · 12 min read · Performance engineering, Query engines, Hardware, Analytics & OLAP
  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.
- [Platform-independent SIMD in Go](https://swe.quest/articles/platform-independent-simd-in-go-f8d408cca35d2358.md): The Go Blog · 2026-09-24 · Hard · 18 min read · Go, Performance engineering, Hardware, Compilers, API design
  Go 1.27 adds an experimental, size-agnostic \`simd\` package, loosely modeled on Highway for C++.
- [ClickHouse Cloud on Google Cloud Now Powered by Google Axion Processors: 30–55% Faster Queries, ~15% Fewer Compute Credits](https://swe.quest/articles/clickhouse-cloud-on-google-cloud-now-powered-by-google-axion-processors-30-55-c5e0059b06f012b1.md): ClickHouse · 2026-04-22 · Easy · 5 min read · Hardware, Performance engineering, Cloud platforms, Analytics & OLAP, Cost optimization
  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.
- [Arch-specific SIMD in Go](https://swe.quest/articles/arch-specific-simd-in-go-2992a831c4663686.md): The Go Blog · 2026-10-02 · Hard · 11 min read · Go, Performance engineering, Compilers, Hardware, WebAssembly
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
