News for hackers. Stuff that matters.
Re:When optimising code, never guess, always measure by hyperpape on Wednesday September 05, 2018 @11:20PM (#17923667)
Thanks for the links! However:

Line 1296 is PyNumber_Add(left, right) Line 1495 is PyNumber_InPlaceAdd(left, right)

Those go to:

PyNumber_Add https://github.com/python/cpython/blob/874809ea389e6434787e7...

PyNumber_InPlaceAdd https://github.com/python/cpython/blob/874809ea389e6434787e7...

And those are different, though I can't tell how it should matter.

Re:When optimising code, never guess, always measure by ShroudedNight on Thursday September 06, 2018 @08:16PM (#17930840)
> And perhaps the culprit is that INPLACE_ADD requires more work than BINARY ADD

It would not surprise me if the culprit was instead:

     98 STORE_FAST 2 (a2)
    100 LOAD_FAST  3 (c)
Due to them being the same amalgamated memory location in practice, with the load hitting the in-flight store. But that's more typical of a POWER performance characteristic than an Intel one...
Re:When optimising code, never guess, always measure by ubernostrum on Sunday September 09, 2018 @11:38PM (#17949231)
Here it's worth knowing a bit about how Python manages data.

Each CPython VM stack frame has three tuples associated with it:

* co_consts is the constant/literal names local to the frame

* co_varnames is all other names local to the frame

* co_names is the all nonlocal names referenced in the frame

Under the hood, Python creates a structure called 'fastlocals' which is basically an array of (pointer to) PyObject, where the PyObject at each index of the array is the value corresponding to the name at the same index of co_varnames. LOAD_FAST and STORE_FAST are extremely simple opcodes; they do a tiny bit of error checking, refcount management (increment on load, decrement on store), and then just manipulate 'fastlocals'.

So, for example, 'LOAD_FAST i' consists in its entirety of:

1. Grab the PyObject at fastlocals[i]

2. If it's null, throw an UnboundLocalError

3. Otherwise, increment its refcount and push it to the top of the frame's evaluation stack.