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 Optimized Memcpy

From Leeroopedia


Knowledge Sources
Domains Memory, SIMD
Last Updated 2026-02-08 00:00 GMT

Overview

Hand-optimized memory copying using SIMD instructions and careful algorithm selection.

Description

Standard memcpy performance varies by libc implementation and CPU. Custom memcpy can optimize for specific patterns: small size branches ordered by frequency, overlapping moves for uneven sizes, SSE/AVX for large copies, aligned stores with unaligned loads, loop unrolling. ClickHouse's memcpy avoids glibc symbol versioning issues and PLT overhead while matching or exceeding glibc performance on common data sizes.

Usage

Use when memcpy is a performance bottleneck, to avoid glibc dependencies, or in embedded systems needing optimized copies.

Theoretical Basis

SIMD Instructions: SSE2 (_mm_loadu_si128, _mm_store_si128) copies 16 bytes per instruction.

Alignment: Aligned stores are faster; aligning destination helps even if source is unaligned.

Loop Unrolling: Unrolling 8x uses all SSE registers and reduces loop overhead.

Size Thresholds: Different algorithms optimal for different size ranges (small: 2-16 bytes with overlapping moves, medium: simple loop, large: unrolled aligned).

Related Pages

Page Connections

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