[lit] Avoid calling realpath() for every printed message
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 19 Oct 2020 15:21:10 +0000 (16:21 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 19 Oct 2020 15:21:34 +0000 (16:21 +0100)
I did some profiling of lit while trying to optimize the libc++ test
startup for remote hosts and it turns out that there is a realpath() call
for every message printed and this shows up in the profile.
The inspect.getframeinfo() function calls realpath() internally and
moreover we don't need most of the other information returned from it.
This patch uses inspect.getsourcefile() and os.path.abspath() to remove
../ from the path instead. Not resolving symlinks reduces the startup time
for running a single test with lit by about 50ms for me.

Reviewed By: ldionne, yln
Differential Revision: https://reviews.llvm.org/D89186

llvm/utils/lit/lit/LitConfig.py

index 58011b5..92a4fce 100644 (file)
@@ -165,11 +165,10 @@ class LitConfig(object):
         f = inspect.currentframe()
         # Step out of _write_message, and then out of wrapper.
         f = f.f_back.f_back
-        file,line,_,_,_ = inspect.getframeinfo(f)
-        location = '%s:%d' % (file, line)
-
-        sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
-                                               kind, message))
+        file = os.path.abspath(inspect.getsourcefile(f))
+        line = inspect.getlineno(f)
+        sys.stderr.write('%s: %s:%d: %s: %s\n' % (self.progname, file, line,
+                                                  kind, message))
 
     def note(self, message):
         if not self.quiet: