Commit f2d92284 authored by Pawel Pluciennik's avatar Pawel Pluciennik Committed by Commit Bot

Improve performance of generating histograms.xml

This CL implements IterElementsWithTag to avoid not needed recursion.

On local machine it saved around 1s (from 7.6s to 6.6s).

Bug: 1016281
Change-Id: I0fea65892bc52574fd4e6fd3fd2455ae3ec646e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872052
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709564}
parent 4ac8b448
...@@ -303,9 +303,10 @@ def ExpandHistogramsOWNERS(histograms): ...@@ -303,9 +303,10 @@ def ExpandHistogramsOWNERS(histograms):
Error: Raised if the OWNERS file with the given path does not exist. Error: Raised if the OWNERS file with the given path does not exist.
""" """
email_pattern = re.compile(_EMAIL_PATTERN) email_pattern = re.compile(_EMAIL_PATTERN)
iter_matches = extract_histograms.IterElementsWithTag
for histogram in histograms.getElementsByTagName('histogram'): for histogram in iter_matches(histograms, 'histogram'):
owners = histogram.getElementsByTagName('owner') owners = [owner for owner in iter_matches(histogram, 'owner', 1)]
# owner is a DOM Element with a single child, which is a DOM Text Node. # owner is a DOM Element with a single child, which is a DOM Text Node.
emails_with_dom_elements = set([ emails_with_dom_elements = set([
...@@ -316,12 +317,10 @@ def ExpandHistogramsOWNERS(histograms): ...@@ -316,12 +317,10 @@ def ExpandHistogramsOWNERS(histograms):
# component is a DOM Element with a single child, which is a DOM Text Node. # component is a DOM Element with a single child, which is a DOM Text Node.
components_with_dom_elements = set([ components_with_dom_elements = set([
extract_histograms.NormalizeString(component.childNodes[0].data) extract_histograms.NormalizeString(component.childNodes[0].data)
for component in histogram.getElementsByTagName('component')]) for component in iter_matches(histogram, 'component', 1)])
for index in range(len(owners)): for index, owner in enumerate(owners):
owner = owners[index]
owner_text = owner.childNodes[0].data owner_text = owner.childNodes[0].data
name = histogram.getAttribute('name') name = histogram.getAttribute('name')
if _IsEmailOrPlaceholder(index == 0, owner_text, name): if _IsEmailOrPlaceholder(index == 0, owner_text, name):
continue continue
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
"""A script to merge multiple source xml files into a single histograms.xml.""" """A script to merge multiple source xml files into a single histograms.xml."""
import argparse import argparse
import expand_owners
import xml.dom.minidom import xml.dom.minidom
import expand_owners
import extract_histograms
def GetElementsByTagName(trees, tag): def GetElementsByTagName(trees, tag):
"""Gets all elements with the specified tag from a set of DOM trees. """Gets all elements with the specified tag from a set of DOM trees.
...@@ -19,7 +21,8 @@ def GetElementsByTagName(trees, tag): ...@@ -19,7 +21,8 @@ def GetElementsByTagName(trees, tag):
Returns: Returns:
A list of DOM nodes with the specified tag. A list of DOM nodes with the specified tag.
""" """
return [e for t in trees for e in t.getElementsByTagName(tag)] iterator = extract_histograms.IterElementsWithTag
return list(e for t in trees for e in iterator(t, tag, 2))
def MakeNodeWithChildren(doc, tag, children): def MakeNodeWithChildren(doc, tag, children):
......
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