-
Notifications
You must be signed in to change notification settings - Fork 49
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
Optimization of valid index calculation #498
Comments
If we do this, we should just define a nice, readable macro for it in |
@brandtbucher Do you mean Putting a macro in |
I think Brandt is referring to things like
which I found at line 386 in Python/bytecodes.c. |
That is indeed a similar trick! I found 3 occurrences in
to
|
Does this actually make a difference in practice? Can't the compiler already do this optimization? |
The PR is created is more about consistency than optimization. With optimizations on there is a difference in the generated code (an extra Output of `gdb -batch -ex "disassemble/rs tupleitem" ./python`Main build with optimizations on:
PR build with optimizations on:
System: linux, gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1) |
In
listobject.c
there is an optimization to check whether an index is valid (e.g.0 <= index < N
) using a single comparison.The same optimization is not used in other files such as
tupleobject.c
(except for _collectionsmodule.c)I created a branch with the idea for the
tupleobject.c
since that might be the most performance critical:python/cpython@main...eendebakpt:cpython:list_tuple
I could not measure significant performance improvements on my system, but perhaps there are other systems/compilers where there is a measurable difference.
The text was updated successfully, but these errors were encountered: