Skip to content

Add gearhash, xetchunk and blake3 WASM packages #1500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Jul 10, 2025
Merged

Conversation

coyotte508
Copy link
Member

@coyotte508 coyotte508 commented May 28, 2025

This PR is an experiment to see what a pure-wasm gearhash looks like, using https://www.assemblyscript.org, a language purpose made to generate WASM.

Generating WASM from rust uses a lot of glue, the glue for assembly script seems a lot thinner:

async function instantiate(module, imports = {}) {
  const { exports } = await WebAssembly.instantiate(module, imports);
  return exports;
}
export const {
  memory,
  add,
} = await (async url => instantiate(
  await (async () => {
    const isNodeOrBun = typeof process != "undefined" && process.versions != null && (process.versions.node != null || process.versions.bun != null);
    if (isNodeOrBun) { return globalThis.WebAssembly.compile(await (await import("node:fs/promises")).readFile(url)); }
    else { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); }
  })(), {
  }
))(new URL("debug.wasm", import.meta.url));

It will also be interesting to compare wasm size between pure wasm & from-rust wasm, as well as provide gearhash to the wider JS/NPM ecosystem.

gearhash is a core component of the xet protocol chunking & hashing and a cool piece of tech!

cc @Wauplin @hanouticelina @assafvayner @rajatarya for viz

Note: also added xetChunk and blake3 packages

@coyotte508 coyotte508 marked this pull request as ready for review July 8, 2025 10:23
@coyotte508 coyotte508 changed the title Add gearhash package Add gearhash, xetchunk and blake3 WASM packages Jul 8, 2025
@coyotte508
Copy link
Member Author

Going to merge this

Even if it's not getting used atm due to perf it provides nice reference implems in assembly script

@coyotte508 coyotte508 merged commit 0065d2b into main Jul 10, 2025
5 checks passed
@coyotte508 coyotte508 deleted the gearhash-experiment branch July 10, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant