Skip to content
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

Improve performance for switch in ceval.c when using MSVC #91719

Closed
gvanrossum opened this issue Apr 20, 2022 · 1 comment
Closed

Improve performance for switch in ceval.c when using MSVC #91719

gvanrossum opened this issue Apr 20, 2022 · 1 comment
Labels
performance type-bug

Comments

@gvanrossum
Copy link

@gvanrossum gvanrossum commented Apr 20, 2022

We've received reports of MSVC not generating optimal code, e.g. gh-89279.

One possible improvement would be to get the big switch statement in ceval.c to generate better code. It's been rumored that MSVC will generate essentially a computed goto if all cases are filled.

See my investigations at faster-cpython/ideas#321 (comment)

@gvanrossum gvanrossum added the type-bug label Apr 20, 2022
@AlexWaygood AlexWaygood added the performance label Apr 20, 2022
gvanrossum added a commit that referenced this issue Apr 21, 2022
Apparently a switch on an 8-bit quantity where all cases are
present generates a more efficient jump (doing only one indexed
memory load instead of two).

So we make opcode and use_tracing uint8_t, and generate a macro
full of extra `case NNN:` lines for all unused opcodes.

See faster-cpython/ideas#321 (comment)
@gvanrossum
Copy link
Author

@gvanrossum gvanrossum commented Apr 23, 2022

Fixed by #91718.

@gvanrossum gvanrossum closed this Apr 23, 2022
vstinner added a commit to vstinner/cpython that referenced this issue Apr 25, 2022
Move internal C API from Include/opcode.h to a new
Include/internal/pycore_opcode.h file. Move:

* EXTRA_CASES
* _PyOpcode_Caches
* _PyOpcode_Deopt
* _PyOpcode_Jump
* _PyOpcode_OpName
* _PyOpcode_RelativeJump
vstinner added a commit to vstinner/cpython that referenced this issue Apr 25, 2022
Move the following API from Include/opcode.h (public C API) to a new
Include/internal/pycore_opcode.h header file (internal C API):

* EXTRA_CASES
* _PyOpcode_Caches
* _PyOpcode_Deopt
* _PyOpcode_Jump
* _PyOpcode_OpName
* _PyOpcode_RelativeJump
vstinner added a commit that referenced this issue Apr 25, 2022
Move the following API from Include/opcode.h (public C API) to a new
Include/internal/pycore_opcode.h header file (internal C API):

* EXTRA_CASES
* _PyOpcode_Caches
* _PyOpcode_Deopt
* _PyOpcode_Jump
* _PyOpcode_OpName
* _PyOpcode_RelativeJump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance type-bug
Projects
None yet
Development

No branches or pull requests

2 participants