News for hackers. Stuff that matters.
Re:When Optimising Code, Measure by danybittel on Tuesday January 16, 2024 @05:15AM (#39011593)
There is instruction level parallelism in modern CPUs. They have multiple "calculation units", that do for example addition. If one doesn't depend on the other they get executed at the same time.
Re:When Optimising Code, Measure by epcoa on Tuesday January 16, 2024 @05:52AM (#39011844)
LOL. The amount of machinery going on under the hood in evaluating those expressions in CPython is staggering. A microscopic detail like a single instruction data dependency has nothing to do with it. (How many CPU add instructions are executed just for those statements? Probably hundreds.)

This is much more likely a quirk of the interpreter (or possibly a fucked up test). CPU details are like 10000 feet down.

Re:When Optimising Code, Measure by reitzensteinm on Tuesday January 16, 2024 @06:00AM (#39011898)
You're absolutely right, but laughing at the notion is unnecessarily rude.
Re:When Optimising Code, Measure by epcoa on Tuesday January 16, 2024 @06:06AM (#39011941)
You’re right. Though it is the scenario in my head playing out of someone slaving over an architecture optimization manual while, zoom out, editing Python that was comical, rather than making fun of anyone specifically.
Re:When Optimising Code, Measure by gpderetta on Tuesday January 16, 2024 @06:03AM (#39011923)
But there is no dependency on the expressions on either variant, so there is no reason why the first variant is faster than the second in principle (of course python internals will get in the way and make it hard to reason about performance at all).
Re:When Optimising Code, Measure by reitzensteinm on Tuesday January 16, 2024 @07:17AM (#39012473)
Not sure why you're being downvoted, because you're right.

To back up parent's point, if you compile the code and the resulting assembly is a direct translation, renaming will break the dependency and the CPU will execute the instructions in parallel. Write after read hazard is the applicable section:

https://en.wikipedia.org/wiki/Register_renaming

Re:When Optimising Code, Measure by gpderetta on Tuesday January 16, 2024 @08:00AM (#39012797)
[off topic, but I expect that some amount of downvotes are people misclicking; I know that I found myself correcting many of my own, I wonder how many I don't catch]