Faster embeddings: how we rebuilt the ONNX path in Manticore
TL;DR Highlight
Switching Candle to ONNX Runtime and disabling spinning made Manticore embeddings ~14× faster
Who Should Read
Backend developers running CPU embedding models inside a database or service where INSERT speed is the bottleneck
Core Mechanics
- ONNX Runtime beat Candle by ~14× on average
- Same box (16 cores/32 threads), same all-MiniLM-L12-v2 weights, averaged over the full threads × batch grid.
- The old SentenceTransformers/Candle path ran 5–11 docs/sec; the new ONNX path ran 70–230 docs/sec.
- Turning off intra_op_spinning was the biggest win
- ORT's thread pool spins by default, burning CPU between calls while waiting for work.
- With many small concurrent calls, every core sat at 100% yet throughput was lower than with spinning off.
- One line, with_intra_op_spinning(false), raised throughput and lowered CPU usage.
- Batch inference was actually slower
- Padding mixed-length texts to the longest one makes the model compute on padding tokens.
- Batches of 8, 16 and 32 gave lower throughput than one doc at a time, so they reverted worker-side batching.
- One shared session, no lock
- A Mutex around one session collapses under concurrency, and a session-per-CPU pool multiplies RAM and cold-start time.
- On Linux and macOS ORT's C Run() API is thread-safe, so they share one session lock-free through an unsafe wrapper.
- On Windows they serialize the whole closure with a Mutex because of ORT threading issues.
- For bulk loads, use one client thread with a big batch
- The backend already parallelizes inside the call, so client fan-out only adds overhead.
- 1 thread × batch=64 peaked at 233 docs/sec versus 147 docs/sec for 8 threads × batch=128.
- Single-insert latency dropped too
- About 14 ms with one client and about 56 ms under 8-way concurrent load.
- Candle was at 200+ ms.
Community Reactions
- A commenter says CPUs aren't built for massive parallelism, so batching may not help and can slow things down
- They recommend CPU-specific optimizations.
- They say AVX512_BF16 on Intel could cut inference time 2–3×, and converting ONNX to OpenVINO is easy.
- A commenter argues spinlocks mean claiming a whole core, so they are a bad idea in most shared-core situations
- They say many people get addicted to them for performance.
- A commenter says we need a more robust replacement for all-MiniLM-L12-v2 at the same compute
- They note Q4 quantization works for larger embedding models but are unsure it plays well with ONNX.
- A commenter says ONNX is their first suggestion for CPU speedups
How to Apply
- Add spinning-off to your ORT session options
- Today, find the intra-op spinning setting in your CPU embedding service, set it to false, and compare docs/sec and top CPU usage before and after.
- The effect is biggest for many small concurrent requests.
- Benchmark per-document inference against batching
- Run batch sizes 1, 8 and 32 on the same document set and compare docs/sec.
- Use real texts with varied lengths so the padding cost shows up.
- Switch bulk loads to one thread with big batches
- Replace many small INSERTs from many threads with 32–128 row INSERTs from one thread.
- This applies when the backend already parallelizes inside the call.
- Upgrade Manticore to 27.1.5+ and use an ONNX model
- If you're already on an ONNX model, upgrading is enough; to change models, add a new FLOAT_VECTOR column and run REBUILD EMBEDDINGS.
- Then move reads to the new column and drop the old one.
Try It
# Run in the Manticore Search 27.1.5+ SQL console (mysql client). Adds an ONNX model column to existing table t and rebuilds embeddings
ALTER TABLE t ADD COLUMN v_new FLOAT_VECTOR KNN_TYPE='hnsw' HNSW_SIMILARITY='l2' MODEL_NAME='Xenova/all-MiniLM-L6-v2' FROM='text_field';
ALTER TABLE t REBUILD EMBEDDINGS v_new;
-- After moving reads to v_new, drop the old column
ALTER TABLE t DROP COLUMN v_old;Terminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls