Spun off from https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1107024/34/common-mk/common_utils.py#11.
Even for small scripts which only uses RunCommand to do the equivalent of subprocess.check_output(), cros_build_lib draws in a lot of unnecessary libraries.
Importing of cros_build_lib takes 6x time than subprocess, which is critical for a small program executed many times.
$ python
>>> import sys
>>> len(sys.modules)
45
>>> import chromite.lib.cros_build_lib
>>> len(sys.modules)
312
$ time python -c 'import chromite.lib.cros_build_lib'
real 0m0.198s
user 0m0.140s
sys 0m0.056s
$ time python -c 'import subprocess'
real 0m0.031s
user 0m0.024s
sys 0m0.004s
Comment 1 by vapier@google.com
, Jul 31Labels: OS-Chrome