8000 Garbage collect only when all isolates are idle · Issue #72031 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Garbage collect only when all isolates are idle #72031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking 8000 “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xster opened this issue Dec 9, 2020 · 5 comments
Open

Garbage collect only when all isolates are idle #72031

xster opened this issue Dec 9, 2020 · 5 comments
Labels
dependency: dart Dart team may need to help us engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically platform-ios iOS applications specifically team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@xster
Copy link
Member
xster commented Dec 9, 2020

We're currently signaling the Dart garbage collector to collect when the animator/engine is notifying idle. To avoid one isolate signaling idle and causing a garbage collection which would jank another rendering isolate, alter the logic to let the garbage collection only occur when all isolates are idle.

#71253 partly related.

@xster xster added platform-android Android applications specifically platform-ios iOS applications specifically engine flutter/engine repository. See also e: labels. dependency: dart Dart team may need to help us labels Dec 9, 2020
@xster xster added the P2 Important issues not at the top of the work list label Dec 10, 2020
@dnfield
Copy link
Contributor
dnfield commented Mar 31, 2021

Some additional thoughts here - NotifyIdle does not necessarily force a collection, especially if the deadline is short. However, if it does, there's no guarantee that the collection will happen in that timespan, particularly if a heap compaction is required. It's not abnormal to see a 200-400ms compaction happen in parallel to other work.

If notify idle was called again during this time, I'm pretty sure it wouldn't really matter - the GC is already running. But we already have some issue with a single isolate where the GC threads run at the same priority as the rendering threads, and you get scheduling contention that can cause jank.

@mkustermann
Copy link
Member

However, if it does, there's no guarantee that the collection will happen in that timespan

There's no guarantee, but the VM makes an estimate how long e.g. a compaction would take - and might decide not to do if the given idle time is not enough.

The intent here is to change the idle notification in engine to only trigger after all UI isolates are idle (e.g. have drawn their frame). The idle deadline used would be until the timepoint when the first UI isolate has more work to do.

-> So this wouldn't apply to all isolates, just UI isolates.

@dnfield
Copy link
Contributor
dnfield commented Apr 14, 2021

My data set is small, but the traces I've seen where compaction happens it routinely takes multiple frames (e.g. 200+ ms) to complete. So what I'll see is something like this:

  • Flutter says it has 6 or 7ms left of idle time at the end of frame workload
  • VM says woohoo let's compact!
  • Flutter goes on to animate more frames, only now it has its 4+ threads contending with 2 more compaction threads
  • VM has spawned two worker threads
  • Flutter has now missed frame deadlines because every frame during compaction was more expensive and had scheduling contention.

Lowering the priority of the VM threads relative to the UI/Raster thread should probably help that kind of issue, but it makes it seem moot to me whether all UI isolates have finished or not.

@mkustermann
Copy link
Member

@dnfield You can find the VM's estimation logic here. If it significantly overshoots the idle deadline, maybe the estimate the VM makes needs to be adjusted.

/cc @rmacnak-google

@dnfield
Copy link
Contributor
dnfield commented Apr 14, 2021

Let me put it this way: I have not seen a trace where a compaction happens within a single frame (16ms), let alone within the deadline.

But it's also entirely possible that I see it lining up with NotifyIdle coincidentally, and the VM has just decided "too bad I need to compact anyway now."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency: dart Dart team may need to help us engine flutter/engine repository. See also e: labels. P2 Important issues not at the top of the work list platform-android Android applications specifically platform-ios iOS applications specifically team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

5 participants
0