Skip to content

There are too many ring buffer implementations in the standard library #19231

@ifreund

Description

@ifreund

As of commit e2cbbd0 I count at least 4 separate ring buffer implementations:

  • std.fifo.LinearFifo - most generic, longest existing.
  • std.RingBuffer - used only by zstd implementation but part of the public std API.
  • lib/std/compress/flate/CircularBuffer.zig - internal to inflate implementation.
  • lib/std/compress/lzma/decode/lzbuffer.zig - internal to lzma implementation.

The current std.RingBuffer implementation is not generic and only supports buffers of u8. It also only supports fixed-length ring buffers while std.fifo.LinearFifo supports a dynamically growable buffer. I think one of two things needs to happen here:

  • std.fifo.linearFifo and std.RingBuffer need to make clear the tradeoffs between the APIs/implementations and present a meaningful choice between the two.
  • Either std.fifo.linearFifo or std.RingBuffer should have its functionality merged into the other and be deleted.

The flate and lzma internal ring buffer implementations are both specialized to the code using them which is fine. However, I suspect they could benefit by using a more generic implementation as a backing data structure.

I don't know exactly what the resolution to this issue should look like, quality API design is quite tricky. However, I think it is important to address before stabilizing the standard library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions