-
Notifications
You must be signed in to change notification settings - Fork 6k
[WIP][iOS] Avoid nextDrawable take much time. #38551
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
This seems like it might need more investigation? Opting out of CATransaction should not affect frame rendering time. |
Yes @knopp , this change needs triage and now this PR is just a draft and just show why it behaves like this. Still Needs more investigation O(∩_∩)O |
This seems also fixes flutter/flutter#115036. Is there a benefit of not rendering with transactions? |
I don't know if there is any benefit render without transactions in raster thread (without platform view).... The comment just say I think this change will impact the time we present MetalDrawable successfully. Because only after we present it successfully, another drawable can be swap to swap queue so that we can get nextDrawable. Otherwise the Also. Before we can't see it in DevTools since we didn't put these time into raster time. |
I think the transactions enabled was breaking image picker at some point? |
@knopp Thx for point that out. I will have a check later. O(∩_∩)O |
@luckysmg this is a milestone on iOS! 👏👏👏 But does it fix the janky screen animation issue? I'm referring to that weird behaviour by which we seem to miss first-frame on screen animations. |
Updated: I'm not sure that if we can do something like method swizzing to hook all |
That is unfortunately. Conceivably we might need to do same thing we do on macOS, which is (bit simplified)
|
Thx. I will have a try on that. ^_^ |
Did some try and invesigation. Because the And in bool IOSSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable) const {
if (drawable == nullptr) {
FML_DLOG(ERROR) << "Could not acquire next Metal drawable from the SkSurface.";
return false;
}
auto command_buffer =
fml::scoped_nsprotocol<id<MTLCommandBuffer>>([[command_queue_ commandBuffer] retain]);
[command_buffer.get() commit];
[command_buffer.get() waitUntilScheduled];
// Use sync and we can wait this operation to complete.
dispatch_sync(dispatch_get_main_queue(), ^{
FML_DCHECK([NSThread isMainThread]);
[CATransaction begin];
[CATransaction setDisableActions:YES];
[reinterpret_cast<id<CAMetalDrawable>>(drawable) present];
[CATransaction commit];
});
return true;
}
And it is easy to get dead lock in add-to-app scene..... Maybe I miss something....... |
This shouldn't dead lock on For teardown it is more complicated. The code is structured differently on desktop so I'm not sure how this would translate, but on shutdown, we first call engine/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.mm Lines 105 to 110 in a19cf36
Since this is called from platform thread, it executes all blocks that raster thread is waiting for and then makes sure that raster thread won't block on anything after. |
Have some try. Present on platform thread is ok, emm but when platform thread has some work to do, the drawable will be delayed to be presented, which is worse... Motion more sensitive for users on a mobile phone than on a desktop..... Also, I surprisingly found this change will also work, and seems has no side effect. Maybe can also take a look that. |
WIP & Needs Triage🤔🤔🤔
This needs triage and needs more investigation. Since this change may have side effect, need to check that.
If this change is reasonable, I will modify the code to make it looks can be landed.
Preview
Before
Before.mp4
After
After.mp4
This patch can solve:
Physical devices I using for verify:
These all devices can repo the constant junk bug and junk disappears with this patch:
The Pure Native iOS code to show this mechanism
Demo code
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.