Commit 5741c98c authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Optimize compilation of mojo .cc files that contain no code

When building the 'chrome' target Mojo generates about 680 .cc files
that contain no actual code. Due to the includes that are stamped out
these files collectively take a non-trivial amount of time to compile.
Detecting these files and deleting the #includes saves about ~1,200
to ~2,100 CPU seconds.

The no-code detection doesn't work generically, but it handles the
code which mojo generates.

Bug: 1054626
Change-Id: Icb2feaa0021332e0a6d4c9e5cac314824578cd87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093881Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748711}
parent 27c4b4b7
......@@ -230,12 +230,36 @@ class Generator(object):
full_path = os.path.join(self.output_dir, filename)
WriteFile(contents, full_path)
def OptimizeEmpty(self, contents):
# Look for .cc files that contain no actual code. There are many of these
# and they collectively take a while to compile.
lines = contents.splitlines()
for line in lines:
if line.startswith('#') or line.startswith('//'):
continue
if re.match(r'namespace .* {', line) or re.match(r'}.*//.*namespace',
line):
continue
if line.strip():
# There is some actual code - return the unmodified contents.
return contents
# If we reach here then we have a .cc file with no actual code. The
# includes are therefore unneeded and can be removed.
new_lines = [line for line in lines if not line.startswith('#include')]
if len(new_lines) < len(lines):
new_lines.append('')
new_lines.append('// Includes removed due to no code being generated.')
return '\n'.join(new_lines)
def WriteWithComment(self, contents, filename):
generator_name = "mojom_bindings_generator.py"
comment = r"// %s is auto generated by %s, do not edit" % (filename,
generator_name)
contents = comment + '\n' + '\n' + contents;
if filename.endswith('.cc'):
contents = self.OptimizeEmpty(contents)
self.Write(contents, filename)
def GenerateFiles(self, args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment