Python 3.11はPython 3.10より10〜60%高速

[PR]記事内のアフィリエイトリンクから収入を得る場合があります
  • URLをコピーしました!

S 20220707 104059

Pythonの次期バージョン「Python 3.11」は、現行の「Python 3.10」より平均で25%高速であることがわかりました(Reddit)。

Ubuntu Linux上でGCCを使ってコンパイルし、pyperformance benchmark suiteで測定したところ、CPython 3.10より平均 25%速くなり、作業負荷によっては、最大で10〜60%高速化される可能性があるとのこと。

ベンチマークの結果はこちらで確認可能です。

S 20220707 104443

Python 3.11では、起動の高速化や、ランタイムの高速化、その他の最適化によって、パフォーマンスの向上が図られています。

起動時間を高速化するため、Python 3.11では、Pythonの起動に不可欠なコアモジュールが「凍結」され、コードオブジェクト(およびバイトコード)がインタプリタによって静的に割り当てられるようになりました。モジュールの実行処理のステップが短縮されることで、インタプリタの起動が10-15%高速化しています。これは、特に短時間実行されるプログラムにとって大きなインパクトがあります。

また、ランタイムも高速化されており、これには、Python関数を呼び出すたびに作成され、実行情報を保持するフレームの作成処理の改良が含まれています。古いスタイルのフレームオブジェクトは、ほとんど作成されなくなり、Python関数の呼び出しが大幅に高速化されました。また、Cインタプリタ関数の呼び出しを回避することで、Pythonのインライン関数の呼び出しも高速化されています。

また以下に示す最適化も行われています。

  • Compiler now optimizes simple C-style formatting with literal format
    containing only format codes %s, %r and %a and makes it as
    fast as corresponding f-string expression.
    (Contributed by Serhiy Storchaka in bpo-28307.)

  • “Zero-cost” exceptions are implemented. The cost of try statements is
    almost eliminated when no exception is raised.
    (Contributed by Mark Shannon in bpo-40222.)

  • Pure ASCII strings are now normalized in constant time by unicodedata.normalize().
    (Contributed by Dong-hee Na in bpo-44987.)

  • math functions comb() and perm() are now up
    to 10 times or more faster for large arguments (the speed up is larger for
    larger k).
    (Contributed by Serhiy Storchaka in bpo-37295.)

  • Dict don’t store hash value when all inserted keys are Unicode objects.
    This reduces dict size. For example, sys.getsizeof(dict.fromkeys("abcdefg"))
    becomes 272 bytes from 352 bytes on 64bit platform.
    (Contributed by Inada Naoki in bpo-46845.)

  • re’s regular expression matching engine has been partially refactored,
    and now uses computed gotos (or “threaded code”) on supported platforms. As a
    result, Python 3.11 executes the pyperformance regular expression benchmarks up to 10%
    faster than Python 3.10.

当初10月に予定されていたPython 3.11のリリースが遅れるのではないかとの情報も流れていますが、Python 3.11は、Pythonユーザーにとっては注目のリリースとなりそうです。

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次