July 20, 2026

Bounds? Checked. Comment drama? Unchecked

Eliminating Go bounds checks with unsafe

Go devs flirt with danger to make code faster — and the comments are spiraling

TLDR: The post says Go code can be sped up by removing some built-in safety checks in carefully proven cases, even using risky low-level tools when needed. Commenters instantly turned it into a debate over whether that danger is worth it, why Go makes this so hard, and whether people should benchmark before getting fancy.

A Go programming post about squeezing extra speed out of code by using unsafe tricks somehow turned into a mini comment-section soap opera. The basic idea is simple: Go normally adds safety checks so programs don’t read past the end of a list of data and crash. The author argues that in performance-critical code, those checks can sometimes be safely removed if you can prove they aren’t needed — and if the compiler still won’t cooperate, some developers reach for the scary-looking "unsafe" toolbox.

That was enough to split the crowd into familiar internet camps. One group basically said, "Cool hack, but did you actually measure it?" One commenter immediately asked whether it would make more sense to benchmark with checks on and off before diving into risky pointer magic. Another wanted to know if profile-guided optimization — software that learns where the slow parts are — could make this whole stunt unnecessary. In other words: the eternal developer argument, clever trick vs. prove it first.

Then came the side-quest chaos. One reader asked why Go can’t just let people turn off these checks for one tiny function like Nim does, which is the kind of comment guaranteed to summon language-war energy. Another complained that Go assembly articles are always maddening because the calling conventions and argument order feel backwards, a niche gripe but delivered with enough irritation to be weirdly iconic. And in the middle of all that, one wholesome drive-by appeared: "This was great, thank you!" Even the internet needs a designated calm friend sometimes.

Key Points

  • The article identifies bounds checks elimination as a high-value Go optimization because it reduces instructions and branches in hot paths.
  • It shows that Go adds runtime safety checks for slice indexing, and compares assembly with and without bounds checks using the `-B` flag.
  • The article notes that removing bounds checks can also improve instruction-cache behavior, branch prediction resources, and register pressure.
  • It demonstrates a conventional BCE technique by rewriting code so the compiler can prove accesses are in range using slicing and loop conditions based on `len(a)`.
  • The article introduces unsafe pointer arithmetic as a fallback for cases where conventional compiler-assisted BCE is not enough, assuming the programmer can prove safety.

Hottest takes

"would it make sense to ... profile it with/without the -B flag" — lou1306
"Is there any way in Go to selectively turn off bounds checking" — archargelod
"Articles about GoLang assembly language are particularly vexing" — naruhodo
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.