brainy/src/embeddings/candle-wasm/Cargo.toml
David Snelling bf71317d21 fix: prevent WASM embedding from blocking event loop during highlight()
embedBatch() with large inputs (e.g. 500 chunks from highlight()) runs
a single synchronous WASM forward pass that blocks the event loop for
200-500ms. Split large batches into micro-batches of 20 with setTimeout(0)
yields between each, keeping max blocking per batch to ~10-30ms.

Also change Cargo.toml opt-level from "z" (size) to 3 (speed) for
~15-20% faster WASM inference. Requires WASM rebuild to take effect.
2026-01-27 16:49:26 -08:00

55 lines
1.6 KiB
TOML

[package]
name = "candle-embeddings"
version = "0.1.0"
edition = "2021"
description = "WASM-based sentence embeddings using Candle and all-MiniLM-L6-v2"
license = "MIT"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
# Candle ML framework
candle-core = "0.8"
candle-nn = "0.8"
candle-transformers = "0.8"
# HuggingFace tokenizer with WASM support
# Use unstable_wasm feature which provides fancy-regex instead of onig
tokenizers = { version = "0.20", default-features = false, features = ["unstable_wasm"] }
# WASM bindings
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
js-sys = "0.3"
web-sys = { version = "0.3", features = ["console"] }
# Serialization for model loading
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
# Error handling
anyhow = "1.0"
# Async
futures = "0.3"
# WASM compatibility - force getrandom with js/wasm_js features
# getrandom 0.2 (from tokenizers->rand) needs "js" feature
# getrandom 0.3 (from candle->rand 0.9) needs "wasm_js" feature + rustflags
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
getrandom = { version = "0.3", features = ["wasm_js"] }
[dev-dependencies]
wasm-bindgen-test = "0.3"
[profile.release]
opt-level = 3 # Optimize for speed (~15-20% faster inference, ~1MB larger binary)
lto = true # Link-time optimization
codegen-units = 1 # Single codegen unit for better optimization
panic = "abort" # Abort on panic (smaller binary)
[features]
default = []
simd = [] # Enable SIMD when browser support is available