7 Optimizations (continues on next page) 13 • Optimized the idiom for assignment a temporary variable in comprehensions. Now for y in [expr] in comprehensions is as fast as a simple assignment y = expr . For example: • Optimized signal handling in multithreaded applications. If a thread different than the main thread gets a signal, the bytecode evaluation loop is no longer interrupted at each bytecode instruction to check for pending signals which cannot be handled. Only the main thread of the main interpreter can handle signals. • Optimized the$_{subprocess}$module on FreeBSD using$_{closefrom()}$ . (Contributed by Ed Maste, Conrad Meyer, Kyle Evans, Kubilay Kocak and Victor Stinner in bpo-38061.) • PyLong_FromDouble() is now up to 1.87x faster for values that fit into$_{long}$ . (Contributed by Sergey Fedoseev in bpo-37986.) • A number of Python builtins ( range , tuple , set , frozenset , list , dict ) are now sped up by us- ing PEP 590 vectorcall protocol. (Contributed by Dong-hee Na, Mark Shannon, Jeroen Demeyer and Petr Viktorin in bpo-37207.) • Optimized$_{difference_update()}$ for the case when the other set is much larger than the base set. (Sug- gested by Evgeny Kapun with code contributed by Michele Orrù in bpo-8425.) • Python’s small object allocator ($_{obmalloc.c}$ ) now allows (no more than) one empty arena to remain available for immediate reuse, without returning it to the OS. This prevents thrashing in simple loops where an arena could be created and destroyed anew on each iteration. (Contributed by Tim Peters in bpo-37257.) • floor division of float operation now has a better performance. Also the message of$_{ZeroDivisionError}$ for this operation is updated. (Contributed by Dong-hee Na in bpo-39434.) • Decoding short ASCII strings with UTF-8 and ascii codecs is now about 15% faster. (Contributed by Inada Naoki in bpo-37348.) Here’s a summary of performance improvements from Python 3.4 through Python 3.9: Python version 3.4 3.5 3.63.7 3.8 -------------- --- --- ------ --- Variable and attribute read access: read_local 7.1 7.1 5.45.1 3.9 read_nonlocal 7.1 8.1 5.85.4 4.4 read_global 15.5 19.0 14.3 13.6 7.6 read_builtin 21.1 21.6 18.5 19.0 7.5 read_classvar_from_class 25.6 26.5 20.7 19.5 read_classvar_from_instance 22.8 23.5 18.8 17.1 read_instancevar 32.4 33.1 28.0 26.3 read_instancevar_slots 27.8 31.3 20.8 20.8 read_namedtuple 73.8 57.5 45.0 46.8 read_boundmethod 37.6 37.9 29.6 26.9 Variable and attribute write access: write_local 8.7 9.3 5.55.3 4.3 write_nonlocal 10.5 11.1 5.6 5.54.7 write_global 19.7 21.2 18.0 18.0 write_classvar 92.9 96.0 104.6 102.1 write_instancevar 44.6 45.8 40.0 38.9 write_instancevar_slots 35.6 36.1 27.3 26.6 Previously, the bytecode evaluation loop was interrupted at each instruction until the main thread handles signals. (Contributed by Victor Stinner in bpo-40010.) (Contributed by Serhiy Storchaka in bpo-32856.) Unlike the$_{:=}$ operator this idiom does not leak a variable to the outer scope. sums = [s for s in [0] for x in data for s in [s + x]]