perf: Prefer datetime.fromisoformat over dateutil.parse in Python 3.11+ #657
+10
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This PR changes the behavior of
get_date_helper
to preferdatetime.datetime.fromisoformat
overdateutil.parser
in Python 3.11 or higher.According to https://github.com/closeio/ciso8601/blob/b17984f5b4c6db0ef596b4d31456c8a39ae278ee/why_ciso8601.md,
Since Python 3.11+, the performance of cPython's datetime.fromisoformat is now very good
. I did some quick testing and it seems to be on a par withciso8601
:On Python 3.10 I've got ~37,5s and ~3,5s without and with
ciso8601
installed, respectively. On Python 3.11 I've got ~2,5s and ~2,6s without and withciso8601
installed, respectively.Because
ciso
is no dependency, but an extra, not all users (including me) installed it. With this PR these users will get a better out-of-the-box performance for Python 3.11+ users.Checklist
pytest tests
completes successfully