Closed Bug 1647251 Opened 4 years ago Closed 4 years ago

Starting TB 78 on a profile with many folders gives unresponsive script error

Categories

(Thunderbird :: Folder and Message Lists, defect, P1)

Tracking

(thunderbird_esr78 fixed, thunderbird79 fixed)

RESOLVED FIXED
Thunderbird 79.0
Tracking Status
thunderbird_esr78 --- fixed
thunderbird79 --- fixed

People

(Reporter: jorgk-bmo, Assigned: aleca)

References

(Regression)

Details

(Keywords: perf, regression)

Attachments

(4 files, 1 obsolete file)

A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
Script: chrome://messenger/content/folderPane.js:1730

This could affect may users. Related to bug 1637668?

Assignee: nobody → alessandro
Status: NEW → ASSIGNED
Priority: -- → P1
Attached patch 1647251-folder-props.diff (obsolete) — Splinter Review

I suspect it might be the very slow insertRule() API.
Jorg, are you able to load and try this patch?

Attachment #9158312 - Flags: review?(mkmelin+mozilla)
Attachment #9158312 - Flags: review?(mkmelin+mozilla) → review+
Severity: -- → S1

All right, I did some profiling and found the issue.

Indeed, the sheet.inertRule() API is super slow.
I did a test in loading only 30 folders, which 10 of them have custom colors, and the difference was already glaring:

  • sheet.inertRule(): 212ms to populate the stylesheet, FPS drop to 6, and a visible UI freeze.
  • textContent +=: 108ms to populate the stylesheet, FPS drop to 16, and NO visible UI freeze.

I also improved the code to not loop through collapsed subfolder, and apply the color only when the parent folder gets opened, if any custom color was set, and of course only once.

The appendColor method doesn't run at all if no custom color is present in the folder database, or if the folder already has a custom color set.

Attachment #9158312 - Attachment is obsolete: true
Attachment #9159451 - Flags: review?(mkmelin+mozilla)
Attached image perf.png

Attached is a controlled, reproducible experiment that comes to a diametrically opposite conclusion as to which method is slower. The first half uses 1000 iterations, the second uses 100. Claiming insertRule() is 'super slow' seems super wrong.

Hey alta88, thanks for checking this as well.

I did a similar experiment with a simple HTML file, and I arrived to your same conclusions.
It's very strange as insertRule() is faster in a web page, but slower and causing UI freeze and drop in FPS in Thunderbird.

I'll attach the screenshots from Thunderbird profiling in a bit.
This is very strange.

It's demonstrably not insertRule() that is causing any of that. So let's put that meme to rest. The experiment is in the Tb developer toolbox, not a web page. I've already commented in the regressing bug on the problem being the design.

alta88, so what is the suggestion? To check if the row is outside the viewport and stop iterating then + keep a listener to retrigger setting as the viewport changes?

(I guess, see bug 1637668 comment #51, right?)

Regressed by: 1637668
Attached image performance-TB-UI.png

Here's a performance recording I did to compare how TB handles applying custom colors to 50 folders.

As you can see, using the sheet.insertRule() API causes a bottleneck in the Recalculate Style process.
This doesn't happen when injecting new rules in the stylesheet with textContent +=.

This happens because, whenever we add a new rule, the Recalculate Style process re-evaluates every selector and looks for matches in the DOM.

Indeed, my statement was not correct. The sheet.insertRule() API is not slower, but it's rather the Recalculate Style process getting called every time we add a new rule.

(I guess, see bug 1637668 comment #51, right?)

This design issue is solved in the patch I uploaded, which does the following:

  • Don't loop through all the folders, only trigger the appendColor() when visible folders are generated on startup.
  • Ignore subfolders if the parent is collapsed. Only trigger the appendColor() for subfolders when those become visible.
  • Don't interact with the folder cache property if no custom colour was defined for that folder.
  • Use textContent to avoid the Recalculate Style bottleneck caused by sheet.insertRule().
Comment on attachment 9159451 [details] [diff] [review]
1647251-folder-props.diff

Review of attachment 9159451 [details] [diff] [review]:
-----------------------------------------------------------------

Ok, let's land this.
Attachment #9159451 - Flags: review?(mkmelin+mozilla) → review+

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/06793905fcd8
Fix unresponsive script for Folder color customization. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 80.0
Target Milestone: Thunderbird 80.0 → Thunderbird 79.0

We should uplift this to esr78, not beta, right?

Flags: needinfo?(mkmelin+mozilla)

Yes, we should

Flags: needinfo?(mkmelin+mozilla)
Comment on attachment 9159451 [details] [diff] [review]
1647251-folder-props.diff

[Approval Request Comment]
Regression caused by (bug #): bug 1637668
User impact if declined: Startup performance issues with multiple folders
Testing completed (on c-c, etc.): c-c
Risk to taking this patch (and alternatives if risky): low as it improves the performance and prevents unnecessary interactions with hidden folders
Attachment #9159451 - Flags: approval-comm-esr78?
Comment on attachment 9159451 [details] [diff] [review]
1647251-folder-props.diff

Approved for ESR
Flags: needinfo?(rob)
Attachment #9159451 - Flags: approval-comm-esr78? → approval-comm-esr78+
Flags: needinfo?(rob)
Blocks: 1652279
See Also: → 672835
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: