WeSearch

Finding a needle in a 4 GB haystack: from 0.75 GB/s to 49 GB/s in Go

·15 min read · 0 reactions · 0 comments · 9 views
#programming#performance#go#optimization
⚡ TL;DR · AI summary

A recent exploration in Go programming achieved a significant speedup in reading a large file containing mostly zeros. By optimizing the reading process, the speed increased from 0.75 GB/s to 49 GB/s through various techniques. This exercise highlights the impact of different methods on performance in data processing tasks.

Key facts
Original article
Segflow
Read full at Segflow →
Opening excerpt (first ~120 words) tap to expand

I had a 4 GiB file that’s almost entirely zeros, exactly one non-zero int64 is hiding at offset Size - 8 (the last aligned slot). The task: find that offset, as fast as possible, in Go on Linux.It’s a deliberately silly problem. There’s no parsing, no indexing, no cleverness on the algorithm side. The only thing it measures is how much data we can pull through a CPU per second. Exactly the kind of micro-task that exposes every layer of the stack: the Go runtime, the standard library, the kernel, the page cache, the memory hierarchy, and SIMD, including Go 1.26’s brand-new simd/archsimd package that lets you write AVX-512 in pure Go.Starting from the most obvious os.ReadFile + for range we get 0.75 GB/s.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Segflow.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Segflow