GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Reduce branches in PyUnicode_MAX_CHAR_VALUE by kumaraditya303 · Pull Request #92142 · python/cpython Conversation
Contributor
Offers a minor 5.5 % speed improvement in microbenchmark but less branches are better especially when it can be done with a small lookup table. Benchmark: ./python -m timeit -s "a='🚀'" "a*1000"# Before 2000000 loops, best of 5: 182 nsec per loop # After 2000000 loops, best of 5: 172 nsec per loop
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
kumaraditya303
force-pushed
the
fast-string
branch
from
134c043 to
ca2513a
Compare
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
kumaraditya303
force-pushed
the
fast-string
branch
2 times, most recently
from
504bde2 to
ca2513a
Compare
|
There was an error while loading. Please reload this page.
|
MSVC is failing to compile and test_cppext is failing as C++ does not support designated initializers in array by #91321 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| static const Py_UCS4 max_char_values[] = { | ||
| [PyUnicode_1BYTE_KIND] = 0xffU, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
So just do it the oldfashioned way?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done but I wanted to use designated initializer, it looks better
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Did you benchmark it on a build with PGO and LTO? Could you also compare before/after for 1-byte wide and 2-byte wide strings? On my Mac (in debug mode, so far) the odd thing is that the 2-byte mode is faster than the 1-byte mode.
I also wonder whether having static data inside a static inline function (that's potentially expanded many times) is a good idea.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 0xffffU, /* PyUnicode_2BYTE_KIND */ | ||
| 0, | ||
| 0x10ffffU, /* PyUnicode_4BYTE_KIND */ | ||
| }; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since kind is 3 bits, maybe add extra zero entries for a total of 8?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I do think it's odd that it fails on MSVC, since designated initializers in arrays are supported -- see e.g. Include/internal/pycore_opcode.h. I wonder if MSVC doesn't like having it in a static inline function? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Well the benchmark is so small that pgo and lto gives inconsistent result because of cpu boost and binary layout. I reject this as this is insignificant and not worth it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Okay, we learned a few things. :-)
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, but lto takes a lot of time to compile and can vary in results up to 5 to 10%.
Linker would de-dedup those in the executable.
MSVC is picky about designated initializers in array in C++ mode, in C mode it works fine. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Got it! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.