(original) (raw)
The EXTENDED\_ARG is included in the multibyte ops, I treat it just like any other operator. Here's a snippet of my hacked-dis.dis output, which made it clear to me that I could just count them as an "operator with word operand."
Line 3000: x = x if x or not x and x is None else x
0001dc83 7c 00 00 LOAD\_FAST x
0001dc86 91 01 00 EXTENDED\_ARG 1
0001dc89 70 9f dc JUMP\_IF\_TRUE\_OR\_POP L1dc9f
0001dc8c 7c 00 00 LOAD\_FAST x
0001dc8f 0c UNARY\_NOT
0001dc90 91 01 00 EXTENDED\_ARG 1
0001dc93 6f 9f dc JUMP\_IF\_FALSE\_OR\_POPL1dc9f
0001dc96 7c 00 00 LOAD\_FAST x
0001dc99 74 01 00 LOAD\_GLOBAL None
0001dc9c 6b 08 00 COMPARE\_OP 'is'
L1dc9f:
0001dc9f 91 01 00 EXTENDED\_ARG 1
0001dca2 72 ab dc POP\_JUMP\_IF\_FALSE L1dcab
0001dca5 7c 00 00 LOAD\_FAST x
0001dca8 6e 03 00 JUMP\_FORWARD L1dcae (+3)
L1dcab:
0001dcab 7c 00 00 LOAD\_FAST x
L1dcae:
0001dcae 7d 00 00 STORE\_FAST x
On Wed, Apr 13, 2016 at 2:23 PM, Victor Stinner <victor.stinner@gmail.com> wrote:
2016-04-13 23:02 GMT+02:00 Eric Fahlgren <ericfahlgren@gmail.com>:
\> Percentage of 1-byte args = 96.80%
Yeah, I expected such high ratio. Good news that you confirm it.
\> Non-argument ops = 53,719
\> One-byte args = 368,787
\> Multi-byte args = 12,191
Again, only a very few arguments take multiple bytes. Good, the
bytecode will be smaller.
IMHO it's more a nice side effect than a real goal. The runtime
performance matters more than the size of the bytecode, it's not like
a bytecode take 4 MB. It's probably closer to 1 KB and so can probably
benefit of the fatest CPU caches.
\> Just for the record, here's my arithmetic:
\> byteCodeSize = 1\*nonArgumentOps + 3\*oneByteArgs + 3\*multiByteArgs
\> wordCodeSize = 2\*nonArgumentOps + 2\*oneByteArgs + 4\*multiByteArgs
If multiByteArgs means any size > 1 byte, the wordCodeSize formula is wrong:
\- no parameter: 2 bytes
\- 8-bit parameter: 2 bytes
\- 16-bit parameter: 4 bytes
\- 24-bit parameter: 6 bytes
\- 32-bit parameter: 8 bytes
But you wrote that you didn't see EXTEND\_ARG, so I guess that
multibyte means 16-bit in your case, and so your formula is correct.
Hopefully, I don't expect 32-bit parameters in the wild, only 24-bit
parameter for function with annotation.
\> (It is interesting to note that I have never encountered an EXTENDED\_ARG operator in the wild, only in my own synthetic examples.)
As I wrote, EXTENDED\_ARG can be seen when MAKE\_FUNCTION is used with
annotations.
Victor