blurhash-rs icon indicating copy to clipboard operation
blurhash-rs copied to clipboard

Add `#[no_std]` and WebAssembly support

Open rubdos opened this issue 1 year ago • 4 comments

Goal is mainly to showcase wasm support.

rubdos avatar Jul 23 '24 13:07 rubdos

Javascript ~~stolen~~ adapted from https://github.com/fpapado/blurhash-rust-wasm

import * as blurhash from "blurhash";

// You can use this to construct canvas-compatible resources
try {
  const pixels = blurhash.decode("LKO2?U%2Tw=w]~RBVZRi};RPxuwH", 40, 30);
  console.log(pixels);
} catch (error) {
  console.log(error);
}
❯ npm run  main

> [email protected] main
> node index.js

Uint8Array(4800) [
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255, 1, 1, 1, 255, 1, 1, 1, 255,
  1, 1, 1, 255,
  ... 4700 more items
]

rubdos avatar Jul 23 '24 15:07 rubdos

blurhash-rs x 6,035 ops/sec ±0.35% (96 runs sampled)
blurhash-rust-wasm x 3,191 ops/sec ±0.70% (95 runs sampled)

meh, ENOTFASTENOUGH :'-)

rubdos avatar Jul 24 '24 08:07 rubdos

> [email protected] main
> node index.js

Uint8Array(4800) [
  252, 194, 161, 255, 252, 194, 161, 255, 251, 193, 162, 255,
  249, 193, 163, 255, 247, 192, 163, 255, 245, 192, 164, 255,
  243, 191, 165, 255, 240, 190, 166, 255, 238, 189, 167, 255,
  235, 188, 168, 255, 233, 187, 168, 255, 231, 186, 168, 255,
  230, 186, 168, 255, 229, 185, 167, 255, 229, 184, 166, 255,
  230, 184, 165, 255, 231, 184, 163, 255, 232, 184, 161, 255,
  234, 184, 158, 255, 237, 185, 156, 255, 239, 185, 154, 255,
  241, 186, 152, 255, 244, 187, 150, 255, 246, 188, 148, 255,
  247, 189, 147, 255,
  ... 4700 more items
]
Uint8Array(4800) [
  251, 193, 161, 255, 251, 193, 161, 255, 250, 193, 161, 255,
  249, 192, 162, 255, 247, 192, 163, 255, 245, 191, 164, 255,
  242, 190, 165, 255, 240, 190, 166, 255, 237, 189, 167, 255,
  235, 188, 167, 255, 232, 187, 168, 255, 231, 186, 168, 255,
  229, 185, 167, 255, 229, 184, 167, 255, 229, 184, 166, 255,
  229, 184, 164, 255, 230, 184, 162, 255, 232, 184, 160, 255,
  234, 184, 158, 255, 236, 184, 156, 255, 239, 185, 153, 255,
  241, 186, 151, 255, 243, 187, 149, 255, 245, 188, 148, 255,
  247, 189, 147, 255,
  ... 4700 more items
]
blurhash-rs decode x 27,498 ops/sec ±0.98% (86 runs sampled)
blurhash-rust-wasm decode x 3,262 ops/sec ±0.40% (95 runs sampled)
Fastest is blurhash-rs decode

🤷

rubdos avatar Jul 24 '24 08:07 rubdos

[2024-07-24T11:05:13.746Z] ['error'] There was an error running the uploader: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 429 - {'detail': ErrorDetail(string='Rate limit reached. Please upload with the Codecov repository upload token to resolve issue. Expected time to availability: 3347s.', code='throttled')}

Ugh.

rubdos avatar Jul 24 '24 11:07 rubdos