| name | swarm-performance |
| description | SIMD optimization, connection pooling, batch APIs, and caching. Use when improving throughput or reducing latency. |
Swarm: Performance
Workflow
- Profile current performance with
cargo bench --bench benchmark
- Identify hot path from flamegraph or benchmark results
- Implement optimization behind feature flag if experimental
- Benchmark before/after with criterion baseline
- Ensure SIMD has scalar fallback for non-SIMD targets
- Run all gates before claiming improvement
SIMD Implementation
#[cfg(all(feature = "simd", nightly))]
use std::simd::u128x2;
pub fn cosine_similarity_simd(&self, other: &Self) -> f32 {
}
Connection Pooling
Use deadpool for async connection pooling, gated for remote Turso only.
Keep per-operation model for local SQLite.
Batch API Pattern
pub async fn inject_concepts(
&self,
concepts: &[(String, HVec10240)]
) -> Result<()> {
}
Caching Pattern
- Prefer cached values stored as
Arc<[T]> so cache hits are cheap (Arc::clone).
- Avoid keying caches via temporary
Vec materializations; hash fixed-size words/arrays directly.
Performance Targets
- Batch similarity: 10k ops/ms
- Connection pool: <1ms acquire time
- Cache hit rate: >80% for repeated access patterns
- Reservoir step: maintain <100μs @ 50k
Test Files
Run performance tests:
cargo test --test <test_name>
LOC Constraint
All files must remain ≤ 500 lines. Refactor to new modules if needed.