[detect_host_arch] Cache HostArch() function

From my recent go/gclient-sync-no-ops analysis, I noticed that
HostArch() is repeated called within get_builtin_vars() fn. The
`platform.architecture()` call made in arm-based systems and some x64 is
expensive and adds to gclient sync's runtime when repeatedly called.

When caching HostArch(), I noticed 22.4% speed-up in incremental no-op
gclient sync when run on arm-based machine.

Change-Id: I962c4fb0879d2931268f5bec1678ef782c56e7f2
Bug: 5076224
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5076226
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
changes/26/5076226/3
Aravind Vasudevan 2 years ago committed by LUCI CQ
parent 8bd4d87e35
commit 8197d724a6

@ -4,10 +4,12 @@
# found in the LICENSE file.
"""Outputs host CPU architecture in format recognized by gyp."""
from functools import lru_cache
import platform
import re
@lru_cache(maxsize=None)
def HostArch():
"""Returns the host architecture with a predictable string."""
host_arch = platform.machine().lower()

@ -47,6 +47,7 @@ class DetectHostArchTest(unittest.TestCase):
platform.machine.return_value = machine
platform.processor.return_value = processor
platform.architecture.return_value = arch
detect_host_arch.HostArch.cache_clear()
self.assertEqual(expected, detect_host_arch.HostArch())

Loading…
Cancel
Save