-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Remove TODO
comment in _pydatetime._isoweek1monday
#127553
Comments
Out of curiosity, is it a debug build or a release+PGO+LTO build? Usually, |
_pydatetime._isoweek1monday
@picnixz I've used the latest debug build. Here I share the result of running cli timeit ↪ ./python.exe -m timeit -s "from timeit_test import _isoweek1monday" "_isoweek1monday(2000)"
500000 loops, best of 5: 407 nsec per loop
↪ ./python.exe -m timeit -s "from timeit_test import _isoweek1monday_new" "_isoweek1monday_new(2000)"
500000 loops, best of 5: 403 nsec per loop |
Ok, that's what I suspect. I'm not sure it's worth the change for the performance part, but it could be worth the change to remove the |
_pydatetime._isoweek1monday
TODO
comment in _pydatetime._isoweek1monday
@picnixz Okay, thanks for the performance review! Apart from the performance, I thought that the new logic is more succinct and easier to understand. Can you agree that the new logic read better? |
Correctness seems to work (I tried for -50000 to +50000) but I haven't done the maths (if someone has time for that, I'd be happy to). Because the condition |
We seldom do these kinds of refactorings. If we did, every now and then someone who disagrees with the former refactoring would appear, and you'd get a constant urge for new refactorings and rewrites. If the code works, let it be. Ditto for code style changes. |
Thanks for the feedback, @erlend-aasland. I get your point about avoiding unnecessary refactorings or changes that might lead to constant revisits. In this case, my primary goal was to address the # XXX comment, as it implies room for improvement. Since the proposed change simplifies the logic without altering functionality or style significantly, I thought it could be worth removing the XXX note and replacing the implementation with something clearer. However, if the preference is to leave the code as is, I’m happy to just remove the XXX comment and keep the current implementation unchanged. Please let me know if that works for you! |
Sorry I didn't reply to this one. The current code has the benefit of being clear in what it does without relying on the fact that some week contains some specific day. But your comment makes it a bit clearer. So I'd say the two implementations weigh the same and I'd prefer just leaving something that works as is. The only thing I would be willing to accept is removing the comment so that future people don't think there is still work to do. |
TODO
comment in _pydatetime._isoweek1monday
TODO
comment in _pydatetime._isoweek1monday
Code and comment are by Alexander Belopolsky, no longer active. To me, timings with normal release non-debug builds are more relevant for production use. Is the 'cli timit' such? |
Thank you for the feedback and insights, everyone! I realize I made an oversight in my earlier performance testing. I apologize for any confusion caused and truly appreciate the time and effort you’ve spent reviewing this. Based on @terryjreedy’s suggestion, I have re-evaluated the performance with additional tests on both debug and optimized builds. Below are the results: Performance TestsProfiling for Single Input (Year = 2000)Without Optimizations
With Optimizations (./configure --enable-optimizations)
Profiling for Various Inputs (Years 1900-2100)Without Optimizations
With Optimizations
Using
|
I'm a bit conflicted. On one's side, we do have a slight improvement but on the other, this only concerns the python implementation. I'm not aware whether non-CPython implementations uses that implementation (maybe PyPy?) but I wouldn't try optimizing Python code that only exists as a fallback. It would be much more meaningful if you can improve the C implementation of this (namely how do we do it in C? is there an equivalent improvement that could be brought?) |
…H-127564) (cherry picked from commit e8b6b39) Co-authored-by: Beomsoo Kim <[email protected]>
…H-127564) (cherry picked from commit e8b6b39) Co-authored-by: Beomsoo Kim <[email protected]>
) (#128501) (cherry picked from commit e8b6b39) Co-authored-by: Beomsoo Kim <[email protected]>
) (#128500) (cherry picked from commit e8b6b39) Co-authored-by: Beomsoo Kim <[email protected]>
Feature or enhancement
Proposal:
According to the existing note
# XXX This could be done more efficiently
, the_isoweek1monday
function can be improved.Current Implementation:
Proposed Change
Replace the current implementation with a simplified logic that is both more performant and easier to understand.
Rationale
The new logic:
1. Aligns directly with the ISO week definition, which makes it easier to comprehend.
2. Reduces unnecessary computations, improving performance slightly.
Validation and Performance Comparison
Using timeit to compare the current and proposed implementations:
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
TODO
comment in_pydatetime._isoweek1monday
#127564The text was updated successfully, but these errors were encountered: