Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.

feat: add snappy binding - #22

Merged
wemeetagain merged 4 commits into
mainfrom
cayman/snappy
Oct 22, 2025
Merged

wemeetagain merged 4 commits into
mainfrom
cayman/snappy

Conversation

@wemeetagain

@wemeetagain wemeetagain commented Oct 20, 2025 •

Copy link
Copy Markdown
Member
  • Add snappy binding, sanity tests, benchmark
  • TODO in another PR, update upstream snappy build to use -O2

@wemeetagain
wemeetagain requested a review from a team as a code owner October 20, 2025 21:54
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @wemeetagain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates Snappy compression and decompression capabilities into the project. It achieves this by adding a Zig FFI binding for the Snappy library, providing a TypeScript wrapper for these functions, and establishing a robust set of tests and benchmarks to validate its functionality and performance. The changes span across build configurations, dependency management, FFI definitions, and new source files for the Snappy implementation and its associated tests and benchmarks.

Highlights

  • Snappy Binding: Introduced a new Snappy compression/decompression binding using Zig's FFI, enabling efficient data handling.
  • Sanity Tests: Added comprehensive sanity tests for the new Snappy functions to ensure correct behavior for compression, uncompression, length calculations, and buffer validation.
  • Performance Benchmarks: Included benchmarks for Snappy operations, comparing the new binding's performance against an existing JavaScript implementation (snappyjs).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces Snappy compression bindings, including the Zig implementation, TypeScript wrappers, tests, and benchmarks. The overall implementation is well-structured. However, I've identified a critical copy-paste error in the TypeScript wrapper that results in incorrect error handling by using an error pointer from the LevelDB binding instead of the one for Snappy. This needs to be corrected to ensure proper error reporting.

Comment thread src/snappy.ts Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@spiral-ladder spiral-ladder left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

on m2 mac without -O2 flag:

bench/snappy.bench.ts
  snappy
    ✔ compress                                                            693481.3 ops/s    1.442000 us/op        -     246689 runs  0.404 s
    ✔ compress (other)                                                     1663894 ops/s    601.0000 ns/op        -    3577853 runs   2.97 s
    ✔ uncompress                                                           1406470 ops/s    711.0000 ns/op        -    1562453 runs   1.41 s
    ✔ uncompress (other)                                                   3546099 ops/s    282.0000 ns/op        -    1535725 runs  0.707 s

with -O2 flag:

bench/snappy.bench.ts
  snappy
    ✔ compress                                                             1862197 ops/s    537.0000 ns/op        -    1969556 runs   1.53 s
    ✔ compress (other)                                                     1686341 ops/s    593.0000 ns/op        -     781233 runs  0.609 s
    ✔ uncompress                                                           3546099 ops/s    282.0000 ns/op        -     992164 runs  0.506 s
    ✔ uncompress (other)                                                   3424658 ops/s    292.0000 ns/op        -    2207266 runs   1.11 s

@spiral-ladder
spiral-ladder self-requested a review October 21, 2025 06:07

@spiral-ladder spiral-ladder left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with ChainSafe/snappy.zig#2 the performance regression should be addressed, though there is probably still more to do there, there are some platform specific optimization flags in the CMakeLists.txt that we're not taking advantage of.

@wemeetagain
wemeetagain merged commit 8f8bc2a into main Oct 22, 2025
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants