[Python-Dev] Python 3.6 dict becomes compact and gets a private version; and keywords become ordered

Serhiy Storchaka storchaka at gmail.com
Thu Sep 15 08:04:04 EDT 2016


On 15.09.16 11:02, INADA Naoki wrote:
> Are two Pythons built with same options?

Both are built from clean checkout with default options (hg update -C 
3.x; ./configure; make -s). The only difference is -std=c99 and 
additional warnings in 3.6:

Python 3.5:
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv 
-O3 -Wall -Wstrict-prototypes    -Werror=declaration-after-statement 
-I. -I./Include    -DPy_BUILD_CORE -o Objects/dictobject.o 
Objects/dictobject.c

Python 3.6:
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv 
-O3 -Wall -Wstrict-prototypes    -std=c99 -Wextra -Wno-unused-result 
-Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include 
   -DPy_BUILD_CORE -o Objects/dictobject.o Objects/dictobject.c

Usually I run a microbenchmark 3-5 times and choose the median. Results 
was stable enough (the variation is about 1%), unlikely the perf tool 
will give significantly different result.

I repeated measurements on different computer, the difference is the same:

Python 3.5: 10 loops, best of 3: 33.5 msec per loop
Python 3.6: 10 loops, best of 3: 37.5 msec per loop

These results look surprisingly and inexplicably to me. I expected that 
even if there is some performance regression in the lookup or modifying 
operation, the iteration should not be slower.

CPUs on both computers work in 32-bit mode. Maybe this affects.


For string keys Python 3.6 is 4 times faster!

$ ./python -m timeit -s "d = dict.fromkeys(map(str, range(10**6)))" -- 
"list(d)"

On one computer:
Python 3.5: 10 loops, best of 3: 384 msec per loop
Python 3.6: 10 loops, best of 3: 94.6 msec per loop

On other computer:
Python 3.5: 10 loops, best of 3: 179 msec per loop
Python 3.6: 10 loops, best of 3: 46 msec per loop




More information about the Python-Dev mailing list