Skip to content

Add gearhash package #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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Add gearhash package #1500

wants to merge 16 commits into from

Conversation

coyotte508
Copy link
Member

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

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