Skip to content

deflate/inflate implementations are ported rather than implemented from first principles #18062

@andrewrk

Description

@andrewrk

Global variables (unacceptable; warrants the "bug" label):

var fixed_huffman_decoder: ?HuffmanDecoder = null;

var corrupt_input_error_offset: u64 = undefined;

What the hell is this comment doing here?

// Optimization. Go compiler isn't smart enough to keep self.b, self.nb in registers,

Requiring an allocator:

fn init(self: *Self, allocator: Allocator, lengths: []u32) !bool {

This implementation is so problematic precisely because it was ported. We can do better by writing these functions from first principles, using Zig's guiding principles and it will be more robust, optimal, and reusable.

In order to close this issue:

  1. Delete the existing deflate/inflate implementation
  2. Make a new implementation that does not require passing an Allocator and is not based on porting existing code. It's ok to look at existing code for inspiration, however. It's fun, and not as hard as you would think. Think about how to do it from first principles and I promise you will make a better implementation than the Go std lib authors.
  3. Suggestion: take advantage of Zig's SIMD features
  4. Provide benchmarks that show the new implementation is significantly faster, better, etc.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions