Hasty Briefsbeta

Bilingual

Too Much Go Misdirection

a year ago
  • #io.Reader
  • #Performance
  • #Go
  • Go's io.Reader interface is commonly used for streaming data, but sometimes direct byte access is needed.
  • The author encounters inefficiency when needing to use bytes directly from an io.Reader, especially with libraries like libavif and libheif.
  • A workaround using type assertion and unsafe.Pointer is attempted to access bytes directly from a bytes.Reader.
  • The image.Decode function complicates this by wrapping the reader in a bufio.Reader if it lacks a Peek method.
  • Further workarounds involve unpacking the bufio.Reader to access the underlying bytes.Reader.
  • Criticism is leveled at Go's structural typing and standard library practices for creating undocumented 'shadow APIs'.
  • The author reflects on the broader implications of such design choices in Go.