perf(encoding): rebase hc positions past u32 boundary#82
Conversation
- store HC table indexes relative to a moving position base - rebase and rebuild live chain/hash entries before u32 overflow - add regression test for post-u32 boundary insertion path - remove obsolete 4 GiB limitation notes for HC levels Closes #51
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR removes the ~4 GiB single-frame degradation for the hash-chain (HC) matcher by rebasing stored hash/chain positions relative to a moving position_base, rebuilding the tables when the relative position space approaches u32 limits.
Changes:
- Reworked
HcMatchGeneratorto store HC table positions as(relative_pos + 1)using aposition_base, with an overflow-safe rebase + live-table rebuild. - Updated docs to remove the previous “>4 GiB limitation” notes for HC-based compression levels.
- Added a regression test intended to cover boundary crossing behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
zstd/src/encoding/mod.rs |
Removes outdated public docs describing the old 4 GiB HC cutoff limitation. |
zstd/src/encoding/match_generator.rs |
Implements HC position rebasing and adds a regression test for u32-boundary crossing. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughHcMatchGenerator now encodes stored positions as offsets relative to a new Changes
Sequence Diagram(s)sequenceDiagram
participant Test as RegressionTest
participant Hc as HcMatchGenerator
participant HT as hash_table
participant CT as chain_table
Test->>Hc: insert_position(abs_pos)
Hc->>Hc: relative = relative_position(abs_pos)
alt relative fits in u32
Hc->>HT: insert_position_no_rebase(relative)
Hc->>CT: update_chain_no_rebase(relative)
else needs rebase
Hc->>Hc: maybe_rebase_positions(abs_pos)
Hc->>HT: clear
Hc->>CT: clear
Hc->>Hc: repopulate by reinserting live history (no_rebase)
Hc->>HT: insert_position_no_rebase(relative)
Hc->>CT: update_chain_no_rebase(relative)
end
Test->>Hc: chain_candidates(query_pos)
Hc->>CT: read candidate_rel
Hc->>Hc: candidate_abs = position_base + candidate_rel
Hc->>Test: return absolute candidates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
- make hc_rebases_positions_after_u32_boundary platform-safe - keep 64-bit >u32 scenario, use boundary path on 32-bit - prevent const arithmetic overflow on i686 CI
- avoid const overflow in i686 by using fallible conversion - clarify relative-position and chain-candidate storage comments
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@zstd/src/encoding/match_generator.rs`:
- Around line 2698-2719: Extend the test hc_rebases_positions_after_u32_boundary
to also verify that chain_candidates returns valid matches after the rebase:
after calling matcher.skip_matching() (which triggers the rebase), invoke
matcher.chain_candidates(current_pos) for one or more positions within the added
data and assert that the returned candidate list contains at least one valid
match (e.g., non-empty and within expected bounds), using HcMatchGenerator
methods add_data, ensure_tables, skip_matching, and chain_candidates to locate
and validate matches; this confirms that rebasing not only updates
position_base/hash_table but preserves matchability.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: f4965f88-60da-4939-b338-7e237c831b85
📒 Files selected for processing (2)
zstd/src/encoding/match_generator.rszstd/src/encoding/mod.rs
💤 Files with no reviewable changes (1)
- zstd/src/encoding/mod.rs
- extend u32-boundary regression to assert chain_candidates returns valid entries - addresses CodeRabbit nitpick on post-rebase matchability
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@zstd/src/encoding/match_generator.rs`:
- Around line 1749-1766: The rebase currently repopulates HC state up to
history_abs_end(), which accidentally inserts not-yet-processed positions and
can change lazy-match behavior; update HcMatchGenerator::maybe_rebase_positions
so after clearing position_base, hash_table, and chain_table it only re-inserts
the already-seen prefix range history_abs_start..abs_pos (use abs_pos as the
upper bound) by calling insert_position_no_rebase for pos in that range, leaving
abs_pos and later positions to be inserted by the caller in normal order; keep
the existing checks (relative_position, position_base assignment, table fills)
intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: d06f78a1-aef2-48b2-98be-767462d9e62f
📒 Files selected for processing (1)
zstd/src/encoding/match_generator.rs
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'structured-zstd vs C FFI (x86_64-gnu)'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.
| Benchmark suite | Current: cd89f8d | Previous: 1f379be | Ratio |
|---|---|---|---|
compress/default/decodecorpus-z000033/matrix/pure_rust |
139.172 ms |
104.909 ms |
1.33 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @polaz
Summary
Validation
Closes #51
Summary by CodeRabbit
Bug Fixes
Documentation