Skip to content

perf(encoding): rebase HC table positions to remove 4 GiB Better level cutoff #51

Description

@polaz

Context

Found during review of #48.

Problem

HcMatchGenerator stores absolute positions as u32. When a single-frame encode exceeds ~4 GiB, insert_position stops inserting (guard at abs_pos >= u32::MAX), and all existing chain candidates become stale within one window slide. Better level degrades to repcode-only matching for the remainder of the stream.

Suggested approach

Periodically rebase stored positions by subtracting a base offset when the u32 range fills up. Keep a position_epoch counter; on rebase, subtract epoch from all live hash/chain entries and update history_abs_start accordingly. This matches C zstd's approach where positions are relative to a sliding base.

Files involved

  • zstd/src/encoding/match_generator.rs (HcMatchGenerator::insert_position, chain_candidates)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumMedium priority — important improvementenhancementNew feature or requestperformancePerformance optimization

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions