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 — Micro-optimize list index range checks by rhettinger · Pull Request #9784 · python/cpython Conversation
Contributor
Old codeNew code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
Is not this like bpo-28397? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It would be interesting to run Linux perf on some representative examples to understand how the function call is affecting cache misses, references and branch predictions. (See #6493 as an example). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| optimization manual found at: | ||
| https://www.agner.org/optimize/optimizing_cpp.pdf | ||
| */ | ||
| return (size_t) i < (size_t) limit; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that the behaviour is well defined in C. I fear that it's Undefined Behaviour. @benjaminp @gpshead: What do you think ?
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.
If it's well defined, why should we hack such micro optimization? Why compilers would not implement the optimization themself?
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.
I think because they don't know that Py_SIZE(op) is non-negative.
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.
It is well defined. It is used for example in the STL implementations.
But there was not found any difference in microbenchmark results on 64-bit platforms in previous discussion in bpo-28397.
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.
Regardless of if this change is measurable, i like the way the code looks afterwards, getting rid of the repeated verbose i < 0 || i >= Py_SIZE(spam) everywhere. so +1 from me.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| static inline int | ||
| valid_index(Py_ssize_t i, Py_ssize_t limit) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why not just define this as taking two size_t parameters instead of doing the casting below. The casts then happen implicitly at all call sites.
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.