Skip to content

Return raw bytes from ZstandardDictionary.Train - #135424

Merged
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/zstandard-dictionary-quality
Oct 13, 2026
Merged

rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/zstandard-dictionary-quality

Conversation

@rzikm

@rzikm rzikm commented Oct 8, 2026

Copy link
Copy Markdown
Member

ZstandardDictionary.Train currently prepares its result at the default compression quality of 3. That prepared dictionary overrides encoder quality, so callers wanting another quality must extract Data and prepare it again.

Return caller-owned dictionary bytes instead, separating offline training/persistence from quality-specific preparation:

byte[] data = ZstandardDictionary.Train(samples, sampleLengths, maxDictionarySize);
using ZstandardDictionary dictionary = ZstandardDictionary.Create(data, quality);

Training validation, the small-sample safety guard, and pooled-buffer cleanup are unchanged. Reference and browser/WASI declarations, documentation, and existing training tests are updated. No new tests remain, and no benchmarks were run.

API review: This is a draft prototype of a source/binary breaking return-type change. It requires API and breaking-change approval before merge; the original approval in #59591 specifies the old ZstandardDictionary return type. Prepared dictionaries still take precedence over encoder quality.

Validation (Windows x64, built through a subst shortcut):

  • dotnet build src\libraries\System.IO.Compression\src\System.IO.Compression.csproj -c Release - passed for all implementation target frameworks with normal ApiCompat validation.
  • dotnet build src\libraries\System.IO.Compression\tests\System.IO.Compression.Tests.csproj -c Release /t:Test - passed: 2,999 normal cases, zero failures/skips. The focused existing dictionary cases also passed, 17/17.
  • The issue reproduction returned the same 11,876 dictionary bytes as the baseline. Explicit preparation at quality 19 produced 5,073 compressed bytes versus 6,312 at quality 3, and round-tripped successfully.

Fixes: #135265

Resolves #135265

Note

This pull request was prepared with GitHub Copilot.

Separate training and persistence from quality-specific dictionary preparation. Synchronize reference and unsupported-platform declarations, update documentation, and migrate the existing training tests.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: ca3e02cc-b75c-48c3-97e1-5c22f1ae2c3a
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@rzikm
rzikm marked this pull request as ready for review October 8, 2026 14:11
@rzikm

rzikm commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Approved by Jeff Schwartz over email to be backported to 11.0 (breaking change doc will be issued)

@rzikm rzikm added the breaking-change Issue or PR that represents a breaking API or functional change over a previous release. label Oct 8, 2026
@dotnet-policy-service dotnet-policy-service Bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 8, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@rzikm

rzikm commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@rzikm backporting to release/11.0 was not run because the source pull request has not been merged. Please merge this pull request before requesting a backport.

@rzikm

rzikm commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@rzikm backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick f9b2095b7beb55ba73ec30e660ee6f1987a44546

Auto-merging src/libraries/System.IO.Compression/ref/System.IO.Compression.cs
Auto-merging src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/Zstandard.PlatformNotSupported.cs
Auto-merging src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/ZstandardDictionary.cs
Auto-merging src/libraries/System.IO.Compression/tests/Zstandard/ZstandardDictionaryTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.IO.Compression/tests/Zstandard/ZstandardDictionaryTests.cs
error: could not apply f9b2095b7be... Return raw bytes from ZstandardDictionary.Train (#135424)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Return raw bytes from ZstandardDictionary.Train
Using index info to reconstruct a base tree...
M	src/libraries/System.IO.Compression/ref/System.IO.Compression.cs
M	src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/Zstandard.PlatformNotSupported.cs
M	src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/ZstandardDictionary.cs
M	src/libraries/System.IO.Compression/tests/Zstandard/ZstandardDictionaryTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.IO.Compression/ref/System.IO.Compression.cs
Auto-merging src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/Zstandard.PlatformNotSupported.cs
Auto-merging src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/ZstandardDictionary.cs
Auto-merging src/libraries/System.IO.Compression/tests/Zstandard/ZstandardDictionaryTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.IO.Compression/tests/Zstandard/ZstandardDictionaryTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Return raw bytes from ZstandardDictionary.Train
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 14, 2026
svick pushed a commit that referenced this pull request Oct 14, 2026
main PR #135424

# Description

`Train` currently returns a dictionary prepared at the default quality,
which can override the quality requested by callers. Return raw
dictionary bytes so callers can prepare the dictionary for their chosen
quality.

- Update the reference API, browser/WASI stubs, documentation, and
existing training test.
- Example:

```csharp
byte[] data = ZstandardDictionary.Train(samples, sampleLengths, maxDictionarySize);
using ZstandardDictionary dictionary = ZstandardDictionary.Create(data, quality: 19);
```

# Customer Impact

Without this change, `Train`-produced dictionaries can prevent callers’
requested compression quality from taking effect.

# Regression

No. `ZstandardDictionary` is new in .NET 11.

# Testing

—

# Risk

This is a breaking public API return-type change. The API shape is
approved; breaking-change documentation remains tracked.

# Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: rzikm <[email protected]>
@rzikm rzikm removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Nov 4, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 68353f15 Deployed Oct 13, 2026 by rzikm via conclusion #10180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO.Compression breaking-change Issue or PR that represents a breaking API or functional change over a previous release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal] Change ZstandardDictionary.Train to return byte[]

2 participants