-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: BSON, Performance
-
None
-
None
-
Python Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Context
While working on PYTHON-5965, I found a performance win that affects the existing
bson. I measured about a 15% improvement on a spawn perf host on the standard bson tests. I measured a 52% encode and 19% decode performance increase for datetime objects using the Howard Hinnant algorithm, which is MIT licensed.
Definition of done
- Replace the time64 library's loop-based calendar math with Hinnant's O(1) algorithm: cbson_timegm64 (encode) iterates year-by-year from 1970 (~8000 iterations for year 9999), and cbson_gmtime64_r (decode) loops per-year.
- Swap millis_from_datetime/datetime_from_millis over to days_from_civil/civil_from_days and drop the time64 sources.
- Remove bson/time64.c|time64.h|time64_config.h|time64_limits.h
- Verify no regression in round trip values
Pitfalls
We need to verify calendar-math correctness across year 1..9999 and negative/epoch boundaries.
Compare the new implementation against the known-good reference across many inputs, AND verify data survives a full encode → decode loop.
Also verify that test_bson_corpus.py passes.
- blocks
-
PYTHON-6109 Stable-ABI (abi3) wheels for Python 3.11+
-
- Needs Triage
-
- is blocked by
-
PYTHON-6096 Add BSON benchmarking regression test support
-
- Needs Triage
-