Closed
Bug 1443230
Opened 6 years ago
Closed 6 years ago
Keep hashtable of interface indexes in xpt.py
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
mozilla60
Tracking | Status | |
---|---|---|
firefox60 | --- | fixed |
People
(Reporter: mccr8, Assigned: mccr8)
References
Details
Attachments
(1 file)
I looked at a profile of running xpt.py on a final link that includes all XPT files. This was for a variant that outputs C++ instead of an XPT file, but I think the performance should be similar. The base time was 2.7 seconds. I noticed a lot of the running time was spent calling a list index, which is done to find the index of an interface. Replacing these index calls with a map from interfaces to their indexes reduced the running time to 1 second. There are also some calls to |interface in self.interfaces| in _sanityCheck which can also be replaced by using this same index map. That reduced the running time further to 0.9 seconds. This does make the code more fragile, because the map has to be updated in parallel with the list, but it doesn't seem too bad to me.
Comment hidden (mozreview-request) |
Comment 2•6 years ago
|
||
mozreview-review |
Comment on attachment 8956213 [details] Bug 1443230 - Keep hashtable of interface indexes in xpt.py. https://reviewboard.mozilla.org/r/225118/#review231208 I think I'd prefer a wrapping type for interfaces, that pretends to be the list type it replaces, rather than relying on callers doing the right thing. Something like: class IndexedList(object): def __init__(self, iterable): self._list = [] self._index_map = {} for i in iterable: self.append(i) def sort(self): self._list.sort() self._index_map = {val: i for i, val in enumerate(self._list, 1)} def append(self, val): self._index_map[val] = len(self._list)] self._list.append(val) def index(self, what): return self._index_map[what] def __contains__(self, what): return what in self._index_map def __iter__(self): return iter(self._list) def __getitem__(self, index): return self._list[index] def __len__(self): return len(self._list)
Attachment #8956213 -
Flags: review?(mh+mozilla)
Assignee | ||
Comment 3•6 years ago
|
||
(In reply to Mike Hommey [:glandium] from comment #2) > I think I'd prefer a wrapping type for interfaces, that pretends to be the > list type it replaces, rather than relying on callers doing the right thing. Oh, wow, that's much better.
Comment hidden (mozreview-request) |
Assignee | ||
Comment 5•6 years ago
|
||
I confirmed locally that I saw the same performance improvements in a regular build without my XPT patches. try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=6a116128b75b03bc81aa011f8cf0ae8e34985da2
Comment 6•6 years ago
|
||
mozreview-review |
Comment on attachment 8956213 [details] Bug 1443230 - Keep hashtable of interface indexes in xpt.py. https://reviewboard.mozilla.org/r/225118/#review231440 ::: xpcom/typelib/xpt/tools/xpt.py:112 (Diff revision 2) > + def __init__(self, iterable): > + self._list = [] > + self._index_map = {} > + for i in iterable: > + self.append(i) > + self._generate_index_map() You don't need this, since you're going through append() to add the contents of iterable, so the index map will already be filled for each elements in there.
Attachment #8956213 -
Flags: review?(mh+mozilla) → review+
Assignee | ||
Comment 7•6 years ago
|
||
(In reply to Mike Hommey [:glandium] from comment #6) > You don't need this, since you're going through append() to add the contents > of iterable, so the index map will already be filled for each elements in > there. Oops, right. I'm not sure why I didn't see that.
Comment hidden (mozreview-request) |
Pushed by amccreight@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/08802a2ae2b5 Keep hashtable of interface indexes in xpt.py. r=glandium
Comment 10•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/08802a2ae2b5
Status: NEW → RESOLVED
Closed: 6 years ago
status-firefox60:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
You need to log in
before you can comment on or make changes to this bug.
Description
•