Closed Bug 1524786 Opened 5 years ago Closed 5 years ago

Fix DeferredTask in new "about:config" and consider reverting the default not to use idleDispatchToMainThread

Categories

(Toolkit :: Async Tooling, defect, P1)

defect

Tracking

()

RESOLVED INACTIVE

People

(Reporter: Paolo, Assigned: Paolo)

References

Details

Attachments

(1 obsolete file)

Bug 1391707 changed DeferredTask to use idleDispatchToMainThread by default, which is not what the new code in "about:config" required. This new default also required a conspicuous number of follow-ups, see bug 1391707 comment 17 onwards.

The purpose of DeferredTask is to coalesce tasks so they don't happen too frequently, with built-in support for asynchronous functions so race conditions don't occur. It also happened to be used for a few operations that can wait until idle.

Here is another case I found with a quick DXR search where waiting indefinitely until an idle callback is likely unintended: https://searchfox.org/mozilla-central/source/mobile/android/modules/geckoview/GeckoViewAutoFill.jsm#61

Florian, what do you think of changing back to a safer default, possibly making the third an "options" argument that looks like:

{ [optional] idleDispatchTimeout: <0 or timeout> }

It's very easy to change current consumers, and it would make the idle timeout explicit preventing misuses in the future. Either way, the documentation in the module should be updated.

Flags: needinfo?(florian)

While looking into this, I noticed that the implementation was actually sub-optimal. Since the idle callback was part of the task, attempts to call "arm" on it during the idle wait (which can be potentially even longer than the coalesce delay) will cause an unnecessary second execution after the next task has completed. I have a patch to fix this and change the default.

Flags: needinfo?(florian)
Assignee: nobody → paolo.mozmail
Status: NEW → ASSIGNED
Priority: -- → P1

Now the task is still considered armed during the idle wait, which prevents unnecessary executions if the "arm" method is called again.

The idle dispatch mode is now selected using a non-default option. The maximum idle timeout is also removed because there are no consumers using it.

Attachment #9041049 - Attachment is obsolete: true

As noted in the review, while there is a 50%-50% split between the use cases, and the class naming could be improved to reflect those separately, I'm closing the bug since it's not relevant in the immediate future.

No longer blocks: 1523028
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: