-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-35723: Proof of concept for tzidx cache #11529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hm, in an earlier version of this I got a segfault when I had some accidental recursion in the I suppose for now I'll assume the segfault was for some other reason and that it is fixed now, but if anyone can come up with an example of a tzinfo implemented with recursion that causes a segfault, I'll add and fix it. |
As with the other tzinfo methods, datetime.tzidx is now implemented in terms of tzinfo.tzidx, with some additional strictness because of the nature of the tzidx method.
|
This PR is stale because it has been open for 30 days with no activity. |
|
I believe this is no longer necessary. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

When examining the performance characteristics of pytz, I realized that pytz's eager calculation of tzname, offset and DST gives it an implicit cache that makes it much faster for repeated queries to .utcoffset(), .dst() and/or .tzname(), see my blog post "pytz: The Fastest Footgun in the West", though the eager calculation means that it's slower to create an aware datetime that never calculates those functions.
This proof of concept introduces a "set once" cache to the
datetimeobject thattzinfoimplementations can use to cache offset and name lookups per datetime. A more thorough discussion of the rationale for this change is available on the associated issue, bpo-35723.I will note that this is currently a WIP, it still needs:
tzidxis not an integer, or outside the interval [0, 254]https://bugs.python.org/issue35723