@@ -1160,33 +1160,52 @@ fcntl
1160
1160
Optimizations
1161
1161
=============
1162
1162
1163
- * Compiler now optimizes simple C-style formatting with literal format
1164
- containing only format codes ``%s ``, ``%r `` and ``%a `` and makes it as
1165
- fast as corresponding f-string expression.
1163
+ This section covers specific optimizations independent of the
1164
+ :ref: `whatsnew311-faster-cpython ` project, which is covered in its own section.
1165
+
1166
+ * The compiler now optimizes simple
1167
+ :ref: `printf-style % formatting <old-string-formatting >` on string literals
1168
+ containing only the format codes ``%s ``, ``%r `` and ``%a `` and makes it as
1169
+ fast as a corresponding :term: `f-string ` expression.
1166
1170
(Contributed by Serhiy Storchaka in :issue: `28307 `.)
1167
1171
1168
- * "Zero-cost" exceptions are implemented. The cost of ``try `` statements is
1169
- almost eliminated when no exception is raised.
1170
- (Contributed by Mark Shannon in :issue: `40222 `.)
1172
+ * Integer division (``// ``) is better tuned for optimization by compilers.
1173
+ It is now around 20% faster on x86-64 when dividing an :class: `int `
1174
+ by a value smaller than ``2**30 ``.
1175
+ (Contributed by Gregory P. Smith and Tim Peters in :gh: `90564 `.)
1171
1176
1172
- * Pure ASCII strings are now normalized in constant time by :func: ` unicodedata.normalize `.
1173
- (Contributed by Dong-hee Na in :issue: ` 44987 `.)
1177
+ * :func: ` sum ` is now nearly 30% faster for integers smaller than `` 2**30 ` `.
1178
+ (Contributed by Stefan Behnel in :gh: ` 68264 `.)
1174
1179
1175
- * :mod: ` math ` functions :func: ` ~math.comb ` and :func: ` ~math.perm ` are now up
1176
- to 10 times or more faster for large arguments (the speed up is larger for
1177
- larger * k *).
1178
- (Contributed by Serhiy Storchaka in :issue: ` 37295 `.)
1180
+ * Resizing lists is streamlined for the common case,
1181
+ speeding up :meth: ` list.append ` by ≈15%
1182
+ and simple :term: ` list comprehension ` \s by up to 20-30%
1183
+ (Contributed by Dennis Sweeney in :gh: ` 91165 `.)
1179
1184
1180
- * Dict don't store hash value when all inserted keys are Unicode objects.
1181
- This reduces dict size. For example, ``sys.getsizeof(dict.fromkeys("abcdefg")) ``
1182
- becomes 272 bytes from 352 bytes on 64bit platform.
1185
+ * Dictionaries don't store hash values when all keys are Unicode objects,
1186
+ decreasing :class: `dict ` size.
1187
+ For example, ``sys.getsizeof(dict.fromkeys("abcdefg")) ``
1188
+ is reduced from 352 bytes to 272 bytes (23% smaller) on 64-bit platforms.
1183
1189
(Contributed by Inada Naoki in :issue: `46845 `.)
1184
1190
1185
- * :mod: `re `'s regular expression matching engine has been partially refactored,
1186
- and now uses computed gotos (or "threaded code") on supported platforms. As a
1187
- result, Python 3.11 executes the `pyperformance regular expression benchmarks
1188
- <https://pyperformance.readthedocs.io/benchmarks.html#regex-dna> `_ up to 10%
1189
- faster than Python 3.10.
1191
+ * Using :class: `asyncio.DatagramProtocol ` is now orders of magnitude faster
1192
+ when transferring large files over UDP,
1193
+ with speeds over 100 times higher for a ≈60 MiB file.
1194
+ (Contributed by msoxzw in :gh: `91487 `.)
1195
+
1196
+ * :mod: `math ` functions :func: `~math.comb ` and :func: `~math.perm ` are now
1197
+ ≈10 times faster for large arguments (with a larger speedup for larger *k *).
1198
+ (Contributed by Serhiy Storchaka in :issue: `37295 `.)
1199
+
1200
+ * The :mod: `statistics ` functions :func: `~statistics.mean `,
1201
+ :func: `~statistics.variance ` and :func: `~statistics.stdev ` now consume
1202
+ iterators in one pass rather than converting them to a :class: `list ` first.
1203
+ This is twice as fast and can save substantial memory.
1204
+ (Contributed by Raymond Hettinger in :gh: `90415 `.)
1205
+
1206
+ * :func: `unicodedata.normalize `
1207
+ now normalizes pure-ASCII strings in constant time.
1208
+ (Contributed by Dong-hee Na in :issue: `44987 `.)
1190
1209
1191
1210
1192
1211
.. _whatsnew311-faster-cpython :
0 commit comments