Closed movermeyer closed 3 years ago
Note that this would give the largest benefits to Python 2.7 users (~3x speedup over using pytz).
Python [3.2, 3.6] can use the Python interface to get access to datetime.timezone
, which is not quite as fast as using the C interface, but still gives nice performance improvements over using pytz. While these versions could still benefit, the amount would not be as much (30% faster over using the Python interface).
Still, if the goal is to be the fastest possible ISO 8601 parser in Python, this is a pretty interesting area of improvement.
Note: we could probably copy Pendulum's implementation.
I've done an experiment where I integrated Pendulum's timezone implementation into ciso8601 v2.0.1
.
The speedups are nearly as dramatic as I estimated above:
That's almost exactly 3 times faster!
(Aside: this flame graph doesn't look as pretty as the others (because of Python 2,7), and is missing pendulum
(due to a regression))
54% faster
Even Python 3.7 benefits
24% faster
Before we can do this, we should confirm that we are able to pickle objects that use pendulum's FixedOffset
timezones. There was a bug related to this raised in another project.
👍 Fixed as part of https://github.com/closeio/ciso8601/pull/58 and https://github.com/movermeyer/backports.datetime_fromisoformat/pull/13
Starting in Python 3.7,
datetime.timezone
objects became accessible through the C-API.ciso8601 v2.0.0 is scheduled to take advantage of this when compiled against Python 3.7+. The performance improvements are dramatic.
ciso8601 should consider creating a C implementation of a tzinfo subclass. This could be a backport of cPython's timezone class, or a new implementation. Having such an implementation would: