Uh oh!
There was an error while loading. Please reload this page.
GH-91719: Make MSVC generate somewhat faster switch code - #91718
Conversation
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). See faster-cpython/ideas#321 (comment)
markshannon
commented
Apr 20, 2022
Would it make more sense to redefine We should probably make |
gvanrossum
commented
Apr 20, 2022
Yeah, I had considered that, it makes sense. I'll confirm that it has the same effect.
I don't see why -- it's not used in a similar switch AFAICT, and it's not cramped for space in its struct. I assume for most other operations the cost of loading an int and loading a byte is effectively the same, since the CPU has to load a whole cache line (32 or 64 bytes) anyway. |
gvanrossum
commented
Apr 20, 2022
I don't believe this needs a news blurb. |
markshannon
commented
Apr 20, 2022
The dispatch sequence includes |
gvanrossum
commented
Apr 20, 2022
Okay, I'll make that change. |
gvanrossum
commented
Apr 20, 2022
@markshannon, please re-review. I confirmed that the switch still uses a single indirection ( |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
markshannon
commented
Apr 21, 2022
Looks good to me |
vstinner
commented
Apr 25, 2022
Oh wow, that's a simple and clever optimization! Great that it helps MSVC to optimize Python on Windows! |
vstinner
commented
Apr 25, 2022
Follow-up fo clean the public API: #91906 |
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).
See faster-cpython/ideas#321 (comment)