Skip to content

Conversation

@iremyux
Copy link
Contributor

@iremyux iremyux commented Nov 19, 2025

This PR adds a WindowSize property to BrotliCompressionOptions to allow developers to configure the Brotli compression window size (valid range: 10-24, default: 22). The window size controls the maximum distance for back-references in the LZ77 algorithm, where larger windows can improve compression for data with long-distance repetitions. Includes corresponding validation tests following the existing pattern established for the Quality property.

Fixes #116227

@iremyux iremyux requested a review from a team November 19, 2025 11:43
@iremyux iremyux self-assigned this Nov 19, 2025
@iremyux iremyux marked this pull request as ready for review November 19, 2025 11:44
Copilot AI review requested due to automatic review settings November 19, 2025 11:44
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

Copilot finished reviewing on behalf of iremyux November 19, 2025 11:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a WindowSize property to the BrotliCompressionOptions class, allowing developers to configure the Brotli compression window size. The window size controls the sliding window size in bits for the LZ77 algorithm, with valid values ranging from 10 to 24 and a default of 22.

  • Added WindowSize property to BrotliCompressionOptions with validation (10-24 range)
  • Integrated window size configuration into BrotliStream compression constructor
  • Added comprehensive test coverage for window size validation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliCompressionOptions.cs Added WindowSize property with validation using BrotliUtils constants
src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliStream.Compress.cs Applied window size configuration to encoder when using compression options
src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs Updated public API reference to include WindowSize property
src/libraries/System.IO.Compression.Brotli/tests/CompressionStreamUnitTests.Brotli.cs Added test to validate window size property including default value and boundary conditions
Comments suppressed due to low confidence (1)

src/libraries/System.IO.Compression.Brotli/src/System/IO/Compression/enc/BrotliCompressionOptions.cs:27

  • The Quality property validation uses hardcoded literals (0, 11) instead of BrotliUtils constants, unlike the WindowSize property which uses BrotliUtils.WindowBits_Min and BrotliUtils.WindowBits_Max. For consistency and maintainability, consider using BrotliUtils.Quality_Min and BrotliUtils.Quality_Max here as well.
                ArgumentOutOfRangeException.ThrowIfLessThan(value, 0, nameof(value));
                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 11, nameof(value));

/// <remarks>
/// The window size is the sliding window size in bits used by the LZ77 algorithm. Larger window sizes can improve compression ratio but use more memory. Range is from 10 to 24. The default value is 22.
/// </remarks>
public int WindowSize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bartonjs I just realized, the Zstandard proposal named similar property Window, and the existing ctor parameter on BrotliEncoder is also called window. I think we should make sure the names are consistent.

Unfortunately, we are already somewhat inconsistent because DeflateStream parameters are called windowBits, but we'd better not add a third name for the same thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like Window is the more naturally aligned name, so it's probably fine to go ahead and use it. Send a blurb to FXDC to see if anyone wants to object.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be able to specify window size in BrotliCompressionOptions and let use large window size as native brotli encoder

3 participants