GitXplorerGitXplorer
e

sledgehammer_bindgen

public
151 stars
8 forks
0 issues

Commits

List of commits on branch master.
Unverified
28482ad209bcc6f203655cfe901a12ea7559a057

bump version

eealmloff committed 5 months ago
Unverified
289727f2e91ecabb4e5655c342e910b694acbe5b

Bump sledgehammer utils

eealmloff committed 5 months ago
Unverified
5c702db9f5a67191b61b9facdcb6f78abfc48a66

bump bindgen macro version

eealmloff committed 6 months ago
Verified
e5d0c67ba19d6abbb304454168b112eb621d887d

Merge pull request #14 from ealmloff/fix-multithreaded

eealmloff committed 6 months ago
Unverified
48f836b3f928e50cedcd478d66cb4b10c1599eca

Fix wasm builds with shared memory

eealmloff committed 6 months ago
Verified
8d8cf3a53d2ccc211e0a7bb19b3c5d09dcb977c5

Merge pull request #13 from ema-fox/patch-1

eealmloff committed 9 months ago

README

The README file for this repository.

sledgehammer bindgen

What is Sledgehammer Bindgen?

Sledgehammer bindgen provides faster rust batched bindings for js code.

How does this compare to wasm-bindgen:

  • wasm-bindgen is a lot more general it allows returning values and passing around a lot more different types of values. For most users wasm-bindgen is a better choice. Sledgehammer is specifically designed for web frameworks that want low-level, fast access to the dom.

  • You can use sledgehammer bindgen with wasm-bindgen. See the docs and examples for more information.

Why is it fast?

String decoding

  • Strings are expensive to decode, but the cost doesn't change much with the size of the string. Wasm-bindgen calls TextDecoder.decode for every string. Sledgehammer only calls TextEncoder.decode once per batch.

  • If the string is small, it is faster to decode the string in javascript to avoid the constant overhead of TextDecoder.decode

  • See this benchmark: https://jsbench.me/4vl97c05lb/5

String Caching

  • You can cache strings in javascript to avoid decoding the same string multiple times.
  • If the string is static sledgehammer will hash by pointer instead of by value.

Byte encoded operations

  • In sledgehammer every operation is encoded as a sequence of bytes packed into an array. Every operation takes 1 byte plus whatever data is required for it.

  • Each operation is encoded in a batch of four as a u32. Getting a number from an array buffer has a high constant cost, but getting a u32 instead of a u8 is not more expensive. Sledgehammer bindgen reads the u32 and then splits it into the 4 individual bytes. It will shuffle and pack the bytes into as few buckets as possible and try to inline reads into js.

  • See this benchmark: https://jsbench.me/csl9lfauwi/2