Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

The Go Blog Unknown date 6 min read Deep dive mediumAdept

A GIF decoder: an exercise in Go interfaces - The Go Programming Language

Go's GIF decoder works by chaining small io.Reader implementations together. A blockReader type strips GIF's length-prefixed sub-blocks into a plain byte stream, and that stream feeds straight into compress/lzw's NewReader, much like a type-safe Unix pipeline. The deblocker pairs a slice with a fixed 256-byte array, so Read never allocates and needs no separate count. Implicit interface satisfaction means the whole decode step is two lines with no glue code.

Related posts

  • A new Go API for JSON

    The Go Blog mediumAdept

    Go 1.27 makes encoding/json/v2 and encoding/json/jsontext stable. They fix long-standing v1 flaws that the Go 1 compatibility promise prevented fixing in place: acceptance of invalid UTF-8 and duplicate object names, nil slices and maps marshaling as null, case-insensitive field matching, and inconsistent MarshalJSON calls. jsontext handles streaming, syntax-only encoding and decoding of tokens and values. v2 builds on it with per-call options, caller-specified marshalers, and streaming MarshalJSONTo/UnmarshalJSONFrom methods. Unmarshal is up to 10x faster while Marshal is roughly at parity, and switching custom unmarshalers to the streaming interfaces can yield orders-of-magnitude gains, as in Kubernetes' kube-openapi.

  • Go Turns 17

    The Go Blog easyNovice

    Go's 17th anniversary recap covers Go 1.26 and 1.27. On the language side, it adds generic methods, self-referential constraints, `new` with an initial value, and nested struct literal keys. In the standard library, `encoding/json/v2` reached GA with up to 10× faster unmarshaling and now backs v1, and a GC-based goroutine leak profiler shipped. Performance work includes the Green Tea GC as default (10–40% less GC overhead), experimental SIMD packages, stack-allocated append backing stores and size-specialized allocation. The release also brings post-quantum TLS/HPKE/ML-DSA, a 7.5-hour urgent response to the eMudhra weak-key incident, and tooling built for humans and AI agents: `go fix` modernizers, `//go:fix inline`, gopls MCP and the pkg.go.dev API.

  • Go Concurrency Patterns: Pipelines and cancellation - The Go Programming Language

    The Go Blog mediumAdept

    Go pipelines are built as stages of goroutines connected by channels, with fan-out to spread work across workers and fan-in (via a sync.WaitGroup-based merge) to combine results. When downstream stages stop reading early, upstream senders block forever and leak goroutines. Sizing buffers to avoid this is fragile. The robust fix is a shared done channel that is closed (via defer) to broadcast cancellation, with every send wrapped in a select. The patterns are applied to a parallel MD5 digest of a directory tree.

  • Platform-independent SIMD in Go

    The Go Blog hardMaster

    Go 1.27 adds an experimental, size-agnostic `simd` package, loosely modeled on Highway for C++. It hides differences in vector width, masking schemes and instruction sets across AVX/AVX2/AVX512, NEON and wasm, and falls back to emulation on platforms without SIMD support. Vector types such as `simd.Float32s` have no fixed length; they load from and store to slices and expose only operations in the cross-platform intersection, with gaps filled by emulation. When an operation is missing, code can drop into the architecture-specific `archsimd` package via `ToArch()`/`FromArch`, and the compiler specializes away the type switch, as shown with a lookup-table popcount implementation for AVX/AVX2.

  • Arch-specific SIMD in Go

    The Go Blog hardMaster

    Go 1.27 extends the experimental architecture-specific SIMD API (simd/archsimd, enabled with GOEXPERIMENT=simd) from amd64 to arm64 NEON and wasm 128-bit SIMD. The design uses typed vector structs, readable method names unified across architectures, opaque mask types that the compiler peepholes into masked instructions, and new zero-cost reinterpretation methods (ToBits, ReshapeToUint<W>s) that replace Go 1.26's As<Type> methods. Worked examples reverse bits with GFNI affine transforms and transpose an 8x8 matrix with AVX2 lane-grouped permutes. Practical advice: guard code with CPU feature checks, which avoid SIGILL and also enable fused AVX-512 lowering; write loop bounds as i < len-n+1 so bounds checks are eliminated; and pass vectors as separate values rather than arrays or structs so they stay in registers.

The quest for software engineering knowledge.

Look:
Layout: