Skip to content

feat(NODE-7097): use Node.js built-in zstd when available - #5073

Open
tadjik1 wants to merge 2 commits into
mainfrom
NODE-7097
Open

tadjik1 wants to merge 2 commits into
mainfrom
NODE-7097

Conversation

@tadjik1

@tadjik1 tadjik1 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Description

Summary of Changes

Use Node.js built-in zstd (zlib.zstdCompress / zlib.zstdDecompress, Node.js 22.15.0+) when available, falling back to @mongodb-js/zstd otherwise

Tests: interop with @mongodb-js/zstd in both directions, built-in preferred when both are present, fallback when built-in is unavailable

Release Highlight

zstd compression no longer requires @mongodb-js/zstd on Node.js 22.15.0+

The driver now uses Node.js' built-in zstd implementation when it is available. On older Node.js versions it continues to use @mongodb-js/zstd, so no changes are needed for existing setups.

Thanks to @axelonet for the original contribution!

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@tadjik1 tadjik1 mentioned this pull request Oct 8, 2026
5 tasks done
@tadjik1
tadjik1 marked this pull request as ready for review October 8, 2026 13:14
@tadjik1
tadjik1 requested a review from a team as a code owner October 8, 2026 13:14
Copilot AI balanced review requested due to automatic review settings October 8, 2026 13:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation preserves fallback behavior and includes focused coverage for the new selection logic.

0 open findings

What changed in this PR

Adds native Node.js zstd support while retaining the optional package fallback.

Changes:

  • Prefer built-in zstd compression and decompression when available.
  • Add interoperability, preference, compression-level, and fallback tests.
  • Document when @mongodb-js/zstd is required.
File Description
src/​deps.ts Selects built-in zstd or the optional dependency.
test/​unit/​cmap/​wire_protocol/​compression.test.ts Tests interoperability and implementation selection.
test/​mongodb_bundled.ts Exposes the loader to bundled tests.
README.md Updates zstd dependency guidance.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@seanrmilligan seanrmilligan self-assigned this Oct 8, 2026
@seanrmilligan seanrmilligan added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By rewriting this test (and adding another way to do zstd compression) we might be changing the meaning of this string a little.

Should tests under this get a context of 'when the compression library is zlib'? And then, elsewhere, when the compression library is @mongodb-js/zstd?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @seanrmilligan! I renamed them to "when the agreed compressor is zstd" to match the snappy/zlib tests in the same file. The idea is that these tests pass whichever implementation the driver picks: on Node 22.15+ the interop tests check the built-in against @mongodb-js/zstd in both directions, and the separate getZstdLibrary() tests check which implementation is picked.

This branch has not been deployed

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

Labels

Primary Review In Review with primary reviewer, not yet ready for team's eyes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants