Closed Bug 1440334 Opened 6 years ago Closed 6 years ago

SyncedBookmarksMirror should use a jankYielder

Categories

(Firefox :: Sync, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
Firefox 60
Tracking Status
firefox60 --- fixed

People

(Reporter: tcsc, Assigned: tcsc)

References

Details

Attachments

(2 files)

Split off from bug 1435588.

There are a few cases where it is necessary, store() is an obvious one (after bug 1435588 at least), but we probably want to do it during application, and maybe other times as well.
Assignee: nobody → tchiovoloni
Comment on attachment 8953187 [details]
Bug 1440334 - (part 1) Add an iterator wrapper to services-common/async.js that uses a jankYielder for you

https://reviewboard.mozilla.org/r/222470/#review228438

Spiffy!
Attachment #8953187 - Flags: review?(kit) → review+
Priority: -- → P1
Comment on attachment 8953188 [details]
Bug 1440334 - (part 2) Yield to the event loop more in SyncedBookmarksMirror.

https://reviewboard.mozilla.org/r/222472/#review228440

Thanks!

I'm wondering if all these periodic dispatches to the main thread are going to hurt us in other ways, and I wish there were an easier way to chunk work...idle dispatch and workers don't *quite* do everything we're looking for, and I suspect the Right Answer is going to end up being something like, "use Rust or C++ and do it off the main thread". We might be able to cut down on this by splitting the merger out, but I'm saying that from intuition, not from experience.

I don't have any other suggestions, though, and your patch should improve things for large trees...so I think we should take it, and decide later if and how we can improve on "sprinkle some `jankYielder`s into our loops". :-)

::: toolkit/components/places/SyncedBookmarksMirror.jsm:60
(Diff revision 1)
>  
>  ChromeUtils.import("resource://gre/modules/Services.jsm");
>  ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
>  
>  XPCOMUtils.defineLazyModuleGetters(this, {
> +  Async: "resource://services-common/async.js",

Do you know if we have a policy for code in `toolkit/` depending on `services/`? I guess this mattered more in the past, where `toolkit/` was shared among Thunderbird, SeaMonkey, etc., which didn't build `services/`.

In practice, I don't think this matters, and I already see code in `toolkit/{modules, components/extensions, components/reader, components/telemetry}` that depends on `services/`.

::: toolkit/components/places/SyncedBookmarksMirror.jsm:3039
(Diff revision 2)
>     * Creates a bookmark node from this merged node.
>     *
>     * @return {BookmarkNode}
>     *         A node containing the decided value and structure state.
>     */
> -  toBookmarkNode() {
> +  async toBookmarkNode() {

Since all its inputs are in memory, I wonder if we should consider moving the merger into a chrome worker. (We should, of course, also fix the obvious issues, like the one you found where we repeatedly loop over the same siblings when deduping). I don't know what the cloning overhead is going to be like, and logging is going to be interesting, but that might remove a source of jank and cut down on yields that we need to do.
Attachment #8953188 - Flags: review?(kit) → review+
Comment on attachment 8953188 [details]
Bug 1440334 - (part 2) Yield to the event loop more in SyncedBookmarksMirror.

https://reviewboard.mozilla.org/r/222472/#review228440

> Do you know if we have a policy for code in `toolkit/` depending on `services/`? I guess this mattered more in the past, where `toolkit/` was shared among Thunderbird, SeaMonkey, etc., which didn't build `services/`.
> 
> In practice, I don't think this matters, and I already see code in `toolkit/{modules, components/extensions, components/reader, components/telemetry}` that depends on `services/`.

As you mention there's already plenty of code that depends on it. In practice, I can't see why someone would import SyncedBookmarksMirror and expect it to work without `services/*` anyway.

> Since all its inputs are in memory, I wonder if we should consider moving the merger into a chrome worker. (We should, of course, also fix the obvious issues, like the one you found where we repeatedly loop over the same siblings when deduping). I don't know what the cloning overhead is going to be like, and logging is going to be interesting, but that might remove a source of jank and cut down on yields that we need to do.

Agreed, this isn't a great fix.
Pushed by tchiovoloni@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/91499c345038
(part 1) Add an iterator wrapper to services-common/async.js that uses a jankYielder for you r=kitcambridge
https://hg.mozilla.org/integration/autoland/rev/81cc9bdd0bfc
(part 2) Yield to the event loop more in SyncedBookmarksMirror. r=kitcambridge
https://hg.mozilla.org/mozilla-central/rev/91499c345038
https://hg.mozilla.org/mozilla-central/rev/81cc9bdd0bfc
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 60
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: