Zero-Copy Patterns
Avoid memory copies.
Overview
Zero-copy patterns avoid unnecessary memory copies in performance-critical IO paths. For IO-heavy workloads the dominant cost is not algorithmic; it is the cycles and memory bandwidth spent shuffling bytes between user and kernel space. The discipline replaces those copies with kernel-native primitives.
- Avoid memory copies. Per-IO copy elimination; the dominant CPU cost on hot IO paths.
- sendfile syscall. Per-Linux kernel-direct send; bypasses user-space buffer for file-to-socket transfers.
- splice and tee. Per-Linux pipe-based zero-copy; supports proxy and forwarding patterns without copy.
- mmap plus per-language zero-copy. Memory-map for large files; Go
io.Copy, JavaFileChannel.transferTowhen the runtime supports it.
The approach
The practical approach: profile IO before optimisation, use sendfile where applicable, mmap for large files, prefer language-native zero-copy, document each optimisation. The team’s discipline produces fast IO that is reproducible and reviewable.
- Profile IO. Per-path syscall count and bytes copied; produces the evidence the optimisation needs.
- sendfile where applicable. Per-static-file sendfile; the canonical pattern for serving file content over a socket.
- mmap for large files. Per-large-file mmap; replaces explicit read with virtual-memory-backed access.
- Per-language zero-copy plus documented optimisation. Use language-native zero-copy; per-path rationale committed for operational review.
Why this compounds
Zero-copy discipline compounds across services. Each optimised IO path produces ongoing performance; the team’s runtime expertise grows; new services inherit the patterns.
- Better IO performance. Zero-copy reduces CPU and memory bandwidth; throughput tracks the network limit, not the CPU.
- Better cost efficiency. Less CPU per byte; the same hardware serves more traffic.
- Better engineering culture. Profile-first culture produces evidence-based decisions; speculation gets replaced with syscall data.
- Institutional knowledge. Each path teaches Linux IO; the team’s systems engineering muscle grows.
Zero-copy discipline is an engineering discipline that pays off across years. Nova AI Ops integrates with IO telemetry, surfaces patterns, and supports the team’s performance discipline.