-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-126220: Adapt _lsprof
to Argument Clinic
#126233
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm always happy with fixes via AC, because they're much more scalable.
What's the perf impact here? |
@gaogaotiantian I've never had experience with profiling |
Just do a quick fib() with cprofile and compare it with the previous implementation would do. Maybe also with one without cprofile. |
@gaogaotiantian maybe I did something wrong, but looks like we also got a speedup from my numbers 😅 (I have little idea about how # Test code: ex.py
def test():
def fib():
start, nextn = 0, 1
while True:
yield start
start, nextn = nextn, start + nextn
gen = fib()
for _ in range(100000):
next(gen)
import cProfile
cProfile.run(test.__code__) Running it on
Running on this PR:
Am I missing something? |
Sorry I meant a recursive import time
def fib(n):
if n <= 1:
return 1
return fib(n - 1) + fib(n - 2)
start = time.time()
# enable profiler
fib(24)
# disable profiler
print(time.time() - start) We need to consider the worst case for cprofile, which is when the code has a lot of function calls. We need to know the overhead of the profiler, and how that is compared with before. You can also refer to #103533, there's a profiling code listed. That might give some extra information. Moving to |
It still gives me a perf boost for some reason 🤔 import time
import cProfile
profiler = cProfile.Profile()
def fib(n):
if n <= 1:
return 1
return fib(n - 1) + fib(n - 2)
start = time.perf_counter()
profiler.enable()
fib(30) # 100th
profiler.disable()
print(time.perf_counter() - start)
# Old: 0.9349823750017094
# New: 0.9253051670020795
# 1% faster |
Is the boost stable(reproducible)? |
Yes, it is pretty much the same on m2 macos:
|
Yeah from the result I don't think there's an observable boost. On the other hand, that's good, because no observable regression either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a side note - this needs to be backported to 3.12 as well :) I added the tags so you should be able to just merge it.
@gaogaotiantian sorry, I forgot to highlight it initially. Please, double check params names that I introduced. Are they correct? |
Actually, I have some doubts about the changes for functions that are not crashing. This is a bug fix, which would be backported. I don't think we should mix in the code polish to the PR. Even though I think changing this in As for the argument name, the |
Can we split this PR into 2? One with the changes to only the 4 callbacks, and the other with all the other methods? |
Fair enough, I would split this PR later! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@erlend-aasland maybe you would be interested in double checking the AC part? :) |
We generally do not backport Argument Clinic adaptions; would it be possible to solve the issue without Argument Clinic first, and backport that bugfix; then apply Argument Clinic? |
@erlend-aasland I think that this case is rather special. This is not just "convert X to use AC" type of PR. This PR solves a crash that was caused by incorrect function args handling. Basically, I can use I can go with simple: if (size < REQUIRED_ARGS) {
PyErr_Format(PyExc_TypeError, "got %d arguments, expected %d", ...);
return NULL;
} This will kinda solve this case, but will be rather ugly. |
@erlend-aasland sorry for bothering, but I cannot decode your 👍 reaction :)
:) |
I see, and thanks for the explanation. I think I still would feel better with such workarounds1 for 3.13 and 3.12, and then introduce the Argument Clinic adaptions in 3.14. Mixing features and bugfixes is seldom a good thing. Footnotes
|
Ok, I will open a new PR with the fix we can backport and then rebase this one and apply all AC fixes from the initial version. Thanks for the feedback! 👍 |
Please amend the title to reflect the actual change :) |
_lsprof.Profiler
methods with 0 args_lsprof
to AC
_lsprof
to AC_lsprof
to Argument Clinic
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
I decided to go with the AC, because:
But, I believe it will be slower. If we really want to preserve speed in this case, I can add manual
size
checks forargs
.Refs #103534
_lsprof.Profiler._creturn_callback()
segfaults #126220