Skip to content

Commit 4ac0b86

Browse files
committed
perf: replace calendar.timegm(utctimetuple()) with integer arithmetic in DateType.serialize
Eliminate the intermediate struct_time allocation in DateType.serialize() and Encoder.cql_encode_datetime() by using direct timedelta arithmetic instead of calendar.timegm(v.utctimetuple()). The old code allocated a 9-field time.struct_time named tuple via utctimetuple(), then calendar.timegm() disassembled it back to an epoch integer. The new code subtracts the epoch datetime directly to get a timedelta, then extracts days/seconds/microseconds as integers — zero intermediate object allocations. Handles both naive (treated as UTC) and timezone-aware datetimes. DateType.serialize datetime: 1022 -> 232 ns/call (4.4x faster) DateType.serialize date: 1369 -> 471 ns/call (2.9x faster) BoundStatement.bind (5-col): 4027 -> 3073 ns/call (1.3x faster)
1 parent 64f8d83 commit 4ac0b86

2 files changed

Lines changed: 456 additions & 263 deletions

File tree

0 commit comments

Comments
 (0)