MCPcopy Index your code
hub / github.com/ealmloff/sledgehammer_bindgen

github.com/ealmloff/sledgehammer_bindgen @0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.4.0 ↗ · + Follow
160 symbols 261 edges 14 files 0 documented · 0% updated 5mo ago0.4.0 · 2024-02-27★ 454
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sledgehammer bindgen

Crates.io version

Download

docs.rs docs

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 beter 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

Extension points exported contracts — how you extend this code

Encoder (Interface)
(no doc) [6 implementers]
sledgehammer_bindgen_macro/src/encoder.rs
Encode (Interface)
(no doc) [6 implementers]
sledgehammer_bindgen_macro/src/encoder.rs
CreateEncoder (Interface)
(no doc) [5 implementers]
sledgehammer_bindgen_macro/src/encoder.rs
DynEncode (Interface)
(no doc) [1 implementers]
sledgehammer_bindgen_macro/src/encoder.rs
AnyDynEncode (Interface)
(no doc) [1 implementers]
sledgehammer_bindgen_macro/src/encoder.rs

Core symbols most depended-on inside this repo

get_or_insert_with
called by 42
sledgehammer_bindgen_macro/src/encoder.rs
insert
called by 24
sledgehammer_bindgen_macro/src/encoder.rs
write_rust
called by 14
sledgehammer_bindgen_macro/src/builder.rs
read_js
called by 9
sledgehammer_bindgen_macro/src/builder.rs
builder
called by 5
sledgehammer_bindgen_macro/src/encoder.rs
flag
called by 5
sledgehammer_bindgen_macro/src/builder.rs
size
called by 5
sledgehammer_bindgen_macro/src/types/numbers.rs
parse_js_body
called by 4
sledgehammer_bindgen_macro/src/function.rs

Shape

Method 84
Function 45
Class 22
Interface 5
Enum 4

Languages

Rust100%

Modules by API surface

sledgehammer_bindgen_macro/src/encoder.rs33 symbols
sledgehammer_bindgen_macro/src/types/numbers.rs18 symbols
sledgehammer_bindgen_macro/src/types/string.rs17 symbols
examples/wry.rs15 symbols
examples/typed_elements.rs15 symbols
examples/test.rs14 symbols
sledgehammer_bindgen_macro/src/builder.rs12 symbols
sledgehammer_bindgen_macro/src/lib.rs9 symbols
sledgehammer_bindgen_macro/src/types/writable.rs8 symbols
sledgehammer_bindgen_macro/src/types/slice.rs8 symbols
sledgehammer_bindgen_macro/src/function.rs8 symbols
examples/simple.rs3 symbols

For agents

$ claude mcp add sledgehammer_bindgen \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact