From 0ada61ccf3b0326a29b842334e25dfd1fba7777d Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Mon, 27 Apr 2015 17:07:49 -0700 Subject: [PATCH] Bug 1158898 - Cache config.guess output; r=mshal mach dispatch makes separate, independent calls to construct build system state. Part of this resolution is determining the object directory. For environments without an object directory defined, we must execute config.guess to determine the object directory. This redundant execution of config.guess can result in significant execution overhead. Before this patch, `mach help` with no mozconfig took ~1.5s on my OS X machine. After this patch, it goes down to ~0.750s. On Windows, the difference is even more pronounced, with execution time dropping from 8.5s to 0.930s. --- python/mozbuild/mozbuild/base.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index ec012fe8d2a..7dde8004aac 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -28,6 +28,9 @@ from .mozconfig import ( from .virtualenv import VirtualenvManager +_config_guess_output = [] + + def ancestors(path): """Emit the parent directories of a path.""" while path: @@ -353,6 +356,11 @@ class MozbuildObject(ProcessExecutionMixin): if config_guess: return config_guess + # config.guess results should be constant for process lifetime. Cache + # it. + if _config_guess_output: + return _config_guess_output[0] + p = os.path.join(topsrcdir, 'build', 'autoconf', 'config.guess') # This is a little kludgy. We need access to the normalize_command @@ -362,7 +370,9 @@ class MozbuildObject(ProcessExecutionMixin): o = MozbuildObject(topsrcdir, None, None, None) args = o._normalize_command([p], True) - return subprocess.check_output(args, cwd=topsrcdir).strip() + _config_guess_output.append( + subprocess.check_output(args, cwd=topsrcdir).strip()) + return _config_guess_output[0] def notify(self, msg): """Show a desktop notification with the supplied message