Optimize consumers of slow gBrowser.visibleTabs
Categories
(Firefox :: Tabbed Browser, task, P3)
Tracking
()
People
(Reporter: Oriol, Unassigned, NeedInfo)
References
(Blocks 1 open bug)
Details
(Keywords: perf:frontend)
get visibleTabs() {
if (!this._visibleTabs) {
this._visibleTabs = Array.prototype.filter.call(
this.tabs,
tab => !tab.hidden && !tab.closing
);
}
return this._visibleTabs;
},
This getter is used very frequently, and it's slow when there are lots of tabs. The result is cached, but that won't help when e.g. removing a thousand of tabs, since each removal will invalidate the cache and do the work again.
It doesn't make sense to do that work just to e.g. check gBrowser.visibleTabs.length === 1
.
Updated•2 years ago
|
Comment 1•1 year ago
|
||
How much of a problem do you think this still is? Bug 1837174 removes another crucial user of this, btw.
Comment 2•1 year ago
|
||
For consumers that have a tab and want to check if it's the only one, a low-effort way to provide that information, without e.g. implementing a visible tab counter, could be to add an isOnlyVisibleTab
property that does something like this:
return !this.hidden &&
!this.closing &&
this.selected &&
this.matches(":nth-child(1 of :not(.tabbrowser-tab[hidden])):nth-last-child(1 of .tabbrowser-tab:not([hidden]))");
I'm not entirely sure it would be a net-win for performance though. If something accesses visibleTabs
shortly after for other purposes, we'd have to rebuild it anyway.
Reporter | ||
Comment 3•1 year ago
|
||
I will have to go back and test perf with some draft patches that I had. Instead of matches()
I was thinking of a lazy computation of visibleTabs
: instead of building the full list, it would only cache as much as needed (so it would stop iterating at the 2nd visible tab if we only need to check if there is a single one).
Updated•1 year ago
|
Description
•