You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Complex decoding: **0.29x** (3.4x slower than C)
284
285
285
-
**Key Findings:**
286
-
- Encoding performance is reasonable for simple documents
287
-
- Main bottleneck: Python/Rust FFI overhead for nested structures
288
-
- Reference Copilot POC achieved 2.89x average speedup primarily through **decoding optimizations** (4-5x faster decode), not encoding
286
+
**Implementation Status:**
287
+
- ✅ Hybrid encoding strategy (fast path for PyDict, `items()` for other mappings)
288
+
- ✅ Direct buffer writing with `doc.to_writer()`
289
+
- ✅ Efficient `_id` field ordering at top level
290
+
- ✅ Direct byte reading for decoding (single-pass bytes → Python dict)
291
+
- ✅ 100% test pass rate (88/88 tests)
289
292
290
-
**Recommendation:** C extension remains the default. Rust extension is available for experimentation and demonstrates feasibility for future development.
293
+
**Performance Analysis:**
294
+
295
+
The Rust extension is currently slower than the C extension for both encoding and decoding. The main bottleneck is **Python FFI overhead** - creating Python objects from Rust incurs significant performance cost.
296
+
297
+
**Recommendation:** C extension remains the default and recommended choice. The Rust extension demonstrates feasibility and correctness but is not yet performance-competitive for production use.
298
+
299
+
### Path to Performance Parity
300
+
301
+
Analysis of the C extension reveals several optimization opportunities to achieve near-parity performance:
302
+
303
+
#### Priority 1: Type Caching (HIGH IMPACT)
304
+
305
+
**Problem:** The Rust implementation calls `py.import()` on every BSON type conversion:
306
+
```rust
307
+
// Called millions of times during decoding!
308
+
letint64_module=py.import("bson.int64")?;
309
+
letint64_class=int64_module.getattr("Int64")?;
310
+
```
311
+
312
+
**Solution:** Cache Python type objects in module state (like C extension does):
0 commit comments