← All stories
● Covered by 1 source · 1 reportMedium impact

Understanding Zero-Copy Techniques and Their Costs in Go

New to BrevFeed? We gather this story from every outlet covering it into one summary — ranked by real-world impact, not just the latest headline — so you never miss what matters. What is BrevFeed? →

Key points

  • Middleware changes can affect Go's zero-copy capabilities.
  • Go's net.TCPConn utilizes sendfile for efficiency.
  • Using wrappers like io.LimitedReader disrupts fast path performance.

Performance Breakdown

In a server environment with specific configurations, a one-line change in middleware led to significant performance degradation. Instead of directly using an os.File with io.Copy, adding a logging reader caused the system to stop utilizing zero-copy optimizations, doubling CPU usage and halving throughput.

Zero-Copy Explained

The sendfile(2) system call in Linux allows for direct transfers from disk to a socket buffer, bypassing user space to improve performance. This avoids the overhead of multiple copies required by traditional read/write operations, making it crucial for high-performance file serving.

Go's Implementation

Go abstracts the zero-copy mechanism with methods such as ReadFrom on *net.TCPConn, which strategically utilizes sendfile when working with os.File. However, if the input is wrapped in another reader type, such as io.LimitedReader, this optimization may be bypassed, leading to inefficiencies.

Conclusion and Best Practices

For developers utilizing Go for file serving, understanding the implications of changes to middleware is crucial. Maintaining direct use of os.File with io.Copy ensures that performance is optimized, leveraging the powerful features provided by the underlying OS.

✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →

The daily brief

One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.

One email a day. Unsubscribe in one click, any time.

Today's brief

Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.

~34 min · 27 stories · Oct 02

▶ Play today's brief Listen on Spotify

New every morning, and the back catalogue is archived by date.

Reporting from

A recent performance issue showed how middleware changes in Go can negate zero-copy optimizations, notably when using io.Copy with os.File. The article details how Go implements zero-copy with methods like sendfile, and the consequences of adding wrappers that disrupt this functionality.