aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2022-12-19 18:45:39 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2022-12-22 23:14:25 +0530
commit5dd3413b717a470955ad0c6603d6d129ce2f5590 (patch)
treef8d61a95f2429867693d26103acb7717e45a4abc
parentc10a76fd95a438cbabf26033dc3d9e154c6e2960 (diff)
downloadmeson-5dd3413b717a470955ad0c6603d6d129ce2f5590.zip
meson-5dd3413b717a470955ad0c6603d6d129ce2f5590.tar.gz
meson-5dd3413b717a470955ad0c6603d6d129ce2f5590.tar.bz2
meson: Cache os.path.realpath in CLikeCompilerArgs
Profiling showed that we were spending 25s inside os.path.realpath() on Windows while generating compile lines for build.ninja, inside NinjaBackend.generate() The real path for these will not (should not) change during a single meson invocation, so cache all these. Brings build.ninja generation from 73s to 47s on my machine.
-rw-r--r--mesonbuild/compilers/mixins/clike.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index 8736c6d..4449aa7 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -101,7 +101,7 @@ class CLikeCompilerArgs(arglist.CompilerArgs):
# Remove system/default include paths added with -isystem
default_dirs = self.compiler.get_default_include_dirs()
if default_dirs:
- real_default_dirs = [os.path.realpath(i) for i in default_dirs]
+ real_default_dirs = [self._cached_realpath(i) for i in default_dirs]
bad_idx_list = [] # type: T.List[int]
for i, each in enumerate(new):
if not each.startswith('-isystem'):
@@ -110,16 +110,21 @@ class CLikeCompilerArgs(arglist.CompilerArgs):
# Remove the -isystem and the path if the path is a default path
if (each == '-isystem' and
i < (len(new) - 1) and
- os.path.realpath(new[i + 1]) in real_default_dirs):
+ self._cached_realpath(new[i + 1]) in real_default_dirs):
bad_idx_list += [i, i + 1]
- elif each.startswith('-isystem=') and os.path.realpath(each[9:]) in real_default_dirs:
+ elif each.startswith('-isystem=') and self._cached_realpath(each[9:]) in real_default_dirs:
bad_idx_list += [i]
- elif os.path.realpath(each[8:]) in real_default_dirs:
+ elif self._cached_realpath(each[8:]) in real_default_dirs:
bad_idx_list += [i]
for i in reversed(bad_idx_list):
new.pop(i)
return self.compiler.unix_args_to_native(new._container)
+ @staticmethod
+ @functools.lru_cache(maxsize=None)
+ def _cached_realpath(arg: str) -> str:
+ return os.path.realpath(arg)
+
def __repr__(self) -> str:
self.flush_pre_post()
return f'CLikeCompilerArgs({self.compiler!r}, {self._container!r})'