STINNER Victor <vstin...@redhat.com> added the comment:

> We're not talking about prefetching here. The Py_LIKELY/Py_UNLIKELY macros 
> only affect which of the two code paths in a branch is the "default" one, 
> i.e. the one not involving a jmp.

I know. My point about prefetching is that if we provide a way to developers to 
tune the compiler, they will use it, but it can lead the a performance 
regression whereas not using these tools would lead to such issue.

> I claim that adding Py_LIKELY/Py_UNLIKELY will reduce the performance 
> randomness of non-PGO builds. So it would be strange to use that randomness 
> as an argument *against* this patch.

It's right that Py_LIKELY/Py_UNLIKELY should make performance more reliable. My 
question is if it is safe to let developers "abuse" it. If these macros are 
misused, they can lead to a performance regression.

I'm not sure that Py_LIKELY/Py_UNLIKELY is always more performant than not 
using it. For example, if you mark the error path as unlikely: this path will 
become slower. If the error path is taken "frequently" enough, the slowdown can 
become significant overall.

It's tricky to decide if a code path is likely or not.

I would be ok to use Py_UNLIKELY for sanity checks which raise SystemError: 
these code paths must never be taken in a valid code. I'm more in favor of 
simply removing these runtime checks in release mode, but that's a different 
issue :-) (bpo-37406)

I'm not sure about judging if the error case raising an exception really 
deserve a Py_UNLIKELY.

Maybe I would be more comfortable if you would split the PR into multiple 
parts. One PR to add the macros. Then one PR per kind of modified tests.

For example, "if (Py_UNLIKELY(tstate->use_tracing))" in ceval.c sounds 
reasonable, but I would prefer to have the opinion of other core devs.

About the macros, I would prefer to make it private to not promote it. It 
should also have a good explanation why it's better to not use it, except if 
you really well understand what you do.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37774>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to