feat: add AdaptiveLevelStrategy for runtime compression level tuning#3391
Merged
feat: add AdaptiveLevelStrategy for runtime compression level tuning#3391
Conversation
9e161f9 to
bfacf36
Compare
This was referenced Apr 26, 2026
Introduces a sender-side strategy that picks per-block compression levels from an EWMA of observed compression ratios so highly compressible payloads get more CPU and incompressible payloads get less. Default implementation is opt-in and wire-compatible: only the encoder level changes, not the protocol or token framing.
bfacf36 to
c3f7e22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AdaptiveLevelStrategytrait +DefaultAdaptiveLevelStrategyincrates/compress/src/strategy/adaptive_level.rsfor sender-side, per-block compression level adaptation.poor_ratio_thresholdratchets level down to save CPU,good_ratio_thresholdratchets level up for better ratio) and clamps to a codec-appropriateLevelBounds(zlib 1..=9, zstd 1..=19).compress::strategyand follows the existing Strategy/Profile module patterns.Test plan
level_bounds_orders_argumentsandlevel_bounds_clamps_within_rangecover bounds construction.first_observation_seeds_ewmacovers EWMA initialisation.monotonic_bad_ratio_decreases_leveldrives 50 incompressible blocks and asserts the level lands atbounds.min.monotonic_good_ratio_increases_leveldrives 50 highly compressible blocks and asserts the level lands atbounds.max.neutral_ratio_holds_levelconfirms ratios between thresholds keep the level steady.ewma_smooths_outlierconfirms a single bad block after good ones moves the smoothed value but does not jump straight to it.reset_clears_history,rejects_non_finite_observation,for_zstd_uses_wider_bounds,alpha_is_clamped_to_unit_intervalcover edge cases.cargo fmt --allclean.