9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python 3.8.0b3 からPGOビルドが速くなる

Last updated at Posted at 2019-07-23

Python をビルドするとき、 configure--enable-optimizations を指定するとビルド時に PGO (Profile Guided Optimization) を利用することができます。

PGO を有効にすると、一度ビルドしたバイナリを実行してプロファイルを取得し、そのプロファイルデータを利用してもう一度最適化ビルドをします。このプロファイル取得のために Python のテストを実行していたのですが、普通のPCでは20分以上かかる上に並列実行することもできませんでした。

--enable-optimizations を指定したときにプロファイル取得に使われるテストを 419 モジュールから 40 モジュールに減らす改善が 取り込まれました。 なので Python 3.8b3 からはPGOを利用したビルドが速くなります。

ちなみに、 --with-lto というオプションを使って LTO (Link Time Optimization) を有効にすると、リンク時間が伸びる代わりにさらに Python の実行速度が向上します。

例えば Ubuntu 19.04, Core i7 6700 で gcc を使って Python をビルドするのにかかる時間はこうなりました。

$ ./configure --enable-optimizations --with-lto; time make -j8

# 改善前
real    29m38.479s
user    33m39.337s
sys     0m53.246s

# 改善後
real    6m50.103s
user    15m55.335s
sys     0m27.544s

例えば pyenv を利用している場合、 CONFIGURE_OPTS 環境変数に --enable-optimizations --with-lto を指定すると速い Python をビルドすることができます。

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?