amazon-ion / ion-python

A Python implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
260 stars 50 forks source link

Optimize Timestamp Reads in ion-c extension #337

Closed rmarrowstone closed 7 months ago

rmarrowstone commented 7 months ago

The first commit refactors Timestamp construction, pulling the heavy-lifting validation and attribute setting logic out into init and leaving the bare minimum in new.

The second commit calls new directly from ionc_read_timestamp and while avoiding building a dict of keyword args.

A benchmark test I put together of all the timestamps from various "vectors" tests shows that this is about 2.7x faster for reading timestamps. The impact to my "hkc" ion benchmark, which features a single Timestamp out of about 15 attributes per top-level-value is roughly a 25% improvement.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.