-
Notifications
You must be signed in to change notification settings - Fork 138
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
feat(speedups): use ciso8601 for deserializing datetimes from the gateway #658
Conversation
@shiftinv did you have an update about the speed on this? |
Yup! Turns out, at least for our purposes (parsing an ISO 8601 timestamp with a $ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000+00:00"; from datetime import datetime; fromisoformat = datetime.fromisoformat' 'fromisoformat(dt)'
.........................................
Mean +- std dev: 86.9 ns +- 4.9 ns
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000+00:00"; from ciso8601 import parse_datetime' 'parse_datetime(dt)'
.........................................
Mean +- std dev: 110 ns +- 6 ns
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000+00:00"; from ciso8601 import parse_rfc3339' 'parse_rfc3339(dt)'
.........................................
Mean +- std dev: 109 ns +- 7 ns While there is no guarantee on the API side about the specific timezone present in the timestamp, it should be pretty safe to assume that it'll always be UTC. It's still noteworthy though that $ python -c 'import sys; print(sys.version)'
3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
$ python -c 'import platform; print(platform.platform())'
Linux-5.17.15-76051715-generic-x86_64-with-glibc2.35
# `+00:00`, same as above
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000+00:00"; from datetime import datetime; fromisoformat = datetime.fromisoformat' 'fromisoformat(dt)'
.........................................
Mean +- std dev: 86.9 ns +- 4.9 ns
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000+00:00"; from ciso8601 import parse_datetime' 'parse_datetime(dt)'
.........................................
Mean +- std dev: 110 ns +- 6 ns
# `-06:00`
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000-06:00"; from datetime import datetime; fromisoformat = datetime.fromisoformat' 'fromisoformat(dt)'
.........................................
Mean +- std dev: 123 ns +- 6 ns
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000-06:00"; from ciso8601 import parse_datetime' 'parse_datetime(dt)'
.........................................
Mean +- std dev: 110 ns +- 6 ns
# no timezone
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000"; from datetime import datetime; fromisoformat = datetime.fromisoformat' 'fromisoformat(dt)'
.........................................
Mean +- std dev: 75.8 ns +- 2.4 ns
$ pyperf timeit --rigorous -s 'dt = "2022-08-13T13:03:23.237000"; from ciso8601 import parse_datetime' 'parse_datetime(dt)'
.........................................
Mean +- std dev: 101 ns +- 5 ns In summary, while I appreciate the idea (#656) of improving performance through new packages, it appears that this one won't result in performance improvements in most cases (and likely lower performance slightly). |
That's a disappointing discovery shiftinv, but thank you @ItsAleph for putting in the work and implementing this feature, even if it doesn't end up providing speed enhancements (which we should've tested before making the issue asking to implement this 😅) |
feat(speedups): use ciso8601 for deserializing datetimes from the gateway
Summary
Resolves #656
Checklist
task lint
task pyright