Bug 223530

Summary: Ignore middle commits during animated resize
Product: WebKit Reporter: Sihui Liu <sihui_liu>
Component: WebKit APIAssignee: Sihui Liu <sihui_liu>
Status: RESOLVED FIXED    
Severity: Normal CC: sam, sihui_liu, simon.fraser, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Sihui Liu 2021-03-19 11:48:18 PDT
...
Comment 1 Sihui Liu 2021-03-19 12:08:59 PDT
Created attachment 423757 [details]
Patch
Comment 2 Sam Weinig 2021-03-19 12:44:57 PDT
It seems like adding SPI for this would only help Safari? Can we instead infer we are in this state somehow instead? Or if really can’t, seems like it should probably be API instead.
Comment 3 Tim Horton 2021-03-19 15:29:55 PDT
I wonder if this is not equivalent to the client calling endAnimatedResize from a doAfterNextPresentationUpdate:^{} block?? It seems like it might be.
Comment 4 Tim Horton 2021-03-19 15:31:00 PDT
(In reply to Sam Weinig from comment #2)
> It seems like adding SPI for this would only help Safari? Can we instead
> infer we are in this state somehow instead? Or if really can’t, seems like
> it should probably be API instead.

Animated resize is SPI, so this doesn't make sense.
Comment 5 Sihui Liu 2021-03-19 16:20:53 PDT
(In reply to Tim Horton from comment #3)
> I wonder if this is not equivalent to the client calling endAnimatedResize
> from a doAfterNextPresentationUpdate:^{} block?? It seems like it might be.

It may be the same. I thought about delaying endAnimatedResize but don't know how much we are going to delay. Let me test if doAfterNextPresentationUpdate:^{} fixes the problem.
Comment 6 Sam Weinig 2021-03-20 11:52:37 PDT
(In reply to Tim Horton from comment #4)
> (In reply to Sam Weinig from comment #2)
> > It seems like adding SPI for this would only help Safari? Can we instead
> > infer we are in this state somehow instead? Or if really can’t, seems like
> > it should probably be API instead.
> 
> Animated resize is SPI, so this doesn't make sense.

Can you elaborate on what you mean by this?
Comment 7 Tim Horton 2021-03-20 12:50:53 PDT
(In reply to Sam Weinig from comment #6)
> (In reply to Tim Horton from comment #4)
> > (In reply to Sam Weinig from comment #2)
> > > It seems like adding SPI for this would only help Safari? Can we instead
> > > infer we are in this state somehow instead? Or if really can’t, seems like
> > > it should probably be API instead.
> > 
> > Animated resize is SPI, so this doesn't make sense.
> 
> Can you elaborate on what you mean by this?

(I was responding to the last sentence; the second one makes sense to me; the first one is just wrong, this isn’t about Safari, but other SPI clients). Animated resize is SPI so it doesn’t make sense to make a mechanism to control a detail of it API?

It’s possible you meant that the whole animated resize SPI should become API (and I vaguely agree), but as it stands the SPI is poorly designed, confusing, and easy to misuse, so that’s a much bigger project.
Comment 8 Sihui Liu 2021-03-21 20:57:43 PDT
It seems we can fix the issue with doAfterNextPresentationUpdate like Tim said, so we don't need the SPI!
Comment 9 Sihui Liu 2021-03-22 01:11:21 PDT
Nope, _doAfterNextPresentationUpdate will invoke callback after ongoing animated resize (see - (void)_internalDoAfterNextPresentationUpdate:(void (^)(void))updateBlock withoutWaitingForPainting:(BOOL)withoutWaitingForPainting withoutWaitingForAnimatedResize:(BOOL)withoutWaitingForAnimatedResize), so if we put _endAnimatedResize in the callback the animated resize will never be ended.
Comment 10 Tim Horton 2021-03-22 01:17:43 PDT
(In reply to Sihui Liu from comment #9)
> Nope, _doAfterNextPresentationUpdate will invoke callback after ongoing
> animated resize (see - (void)_internalDoAfterNextPresentationUpdate:(void
> (^)(void))updateBlock
> withoutWaitingForPainting:(BOOL)withoutWaitingForPainting
> withoutWaitingForAnimatedResize:(BOOL)withoutWaitingForAnimatedResize), so
> if we put _endAnimatedResize in the callback the animated resize will never
> be ended.

Oh, geez.
Comment 11 Sihui Liu 2021-03-22 16:18:52 PDT
Created attachment 423957 [details]
Patch
Comment 12 Tim Horton 2021-03-22 16:26:37 PDT
Comment on attachment 423957 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=423957&action=review

> Source/WebKit/ChangeLog:16
> +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.

>Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize

Doesn't this just mean that you haven't won the race in your testing?? (receiving a commit /after/ Safari calls -endAnimatedResize)
Comment 13 Tim Horton 2021-03-22 16:27:36 PDT
(In reply to Tim Horton from comment #12)
> Comment on attachment 423957 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> 
> > Source/WebKit/ChangeLog:16
> > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> 
> >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> 
> Doesn't this just mean that you haven't won the race in your testing??
> (receiving a commit /after/ Safari calls -endAnimatedResize)

(you could probably win the race by either using slower hardware or putting a short sleep in `RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush` before the call to `sendMessage`)
Comment 14 Sihui Liu 2021-03-22 16:32:56 PDT
(In reply to Tim Horton from comment #13)
> (In reply to Tim Horton from comment #12)
> > Comment on attachment 423957 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> > 
> > > Source/WebKit/ChangeLog:16
> > > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> > 
> > >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> > 
> > Doesn't this just mean that you haven't won the race in your testing??
> > (receiving a commit /after/ Safari calls -endAnimatedResize)
> 
> (you could probably win the race by either using slower hardware or putting
> a short sleep in `RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush`
> before the call to `sendMessage`)

(In reply to Tim Horton from comment #12)
> Comment on attachment 423957 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> 
> > Source/WebKit/ChangeLog:16
> > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> 
> >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> 
> Doesn't this just mean that you haven't won the race in your testing??
> (receiving a commit /after/ Safari calls -endAnimatedResize)

Yes, I don't see commits arrive after Safari calls endAnimatedResize during testing, so I am not sure whether that can happen in a real-world use case.

Will try sleep in RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush() a bit.
Comment 15 Tim Horton 2021-03-22 16:48:01 PDT
(In reply to Sihui Liu from comment #14)
> (In reply to Tim Horton from comment #13)
> > (In reply to Tim Horton from comment #12)
> > > Comment on attachment 423957 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> > > 
> > > > Source/WebKit/ChangeLog:16
> > > > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> > > 
> > > >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> > > 
> > > Doesn't this just mean that you haven't won the race in your testing??
> > > (receiving a commit /after/ Safari calls -endAnimatedResize)
> > 
> > (you could probably win the race by either using slower hardware or putting
> > a short sleep in `RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush`
> > before the call to `sendMessage`)
> 
> (In reply to Tim Horton from comment #12)
> > Comment on attachment 423957 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> > 
> > > Source/WebKit/ChangeLog:16
> > > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> > 
> > >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> > 
> > Doesn't this just mean that you haven't won the race in your testing??
> > (receiving a commit /after/ Safari calls -endAnimatedResize)
> 
> Yes, I don't see commits arrive after Safari calls endAnimatedResize during
> testing, so I am not sure whether that can happen in a real-world use case.

There is no connection between the two (a commit can be arbitrarily delayed in the WP, on a secondary queue, which is what you're going to test), so it should /totally/ be possible.
Comment 16 Sihui Liu 2021-03-23 09:55:23 PDT
(In reply to Tim Horton from comment #15)
> (In reply to Sihui Liu from comment #14)
> > (In reply to Tim Horton from comment #13)
> > > (In reply to Tim Horton from comment #12)
> > > > Comment on attachment 423957 [details]
> > > > Patch
> > > > 
> > > > View in context:
> > > > https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> > > > 
> > > > > Source/WebKit/ChangeLog:16
> > > > > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> > > > 
> > > > >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> > > > 
> > > > Doesn't this just mean that you haven't won the race in your testing??
> > > > (receiving a commit /after/ Safari calls -endAnimatedResize)
> > > 
> > > (you could probably win the race by either using slower hardware or putting
> > > a short sleep in `RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush`
> > > before the call to `sendMessage`)
> > 
> > (In reply to Tim Horton from comment #12)
> > > Comment on attachment 423957 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=423957&action=review
> > > 
> > > > Source/WebKit/ChangeLog:16
> > > > +        _waitingForEndAnimatedResize. In this case, let's just ignore middle commits and remove corresponding code.
> > > 
> > > >Safari, also doesn't hit the adative scaling path because it always early returns at _waitingForEndAnimatedResize
> > > 
> > > Doesn't this just mean that you haven't won the race in your testing??
> > > (receiving a commit /after/ Safari calls -endAnimatedResize)
> > 
> > Yes, I don't see commits arrive after Safari calls endAnimatedResize during
> > testing, so I am not sure whether that can happen in a real-world use case.
> 
> There is no connection between the two (a commit can be arbitrarily delayed
> in the WP, on a secondary queue, which is what you're going to test), so it
> should /totally/ be possible.

I see. With 1s sleep in RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush() I can reproduce the case where middle commits (commits before animated size update and arrive in UI process after beginAnimatedResize) arrive after endAnimatedResize. And it seems removing the code is the correct behavior in Safari, otherwise we can stretch too much.
Comment 17 Sihui Liu 2021-03-23 13:09:00 PDT
Created attachment 424053 [details]
Patch
Comment 18 Tim Horton 2021-03-24 00:30:15 PDT
Comment on attachment 424053 [details]
Patch

Given the results of Sihui's experiments, let's give it a shot.
Comment 19 Radar WebKit Bug Importer 2021-03-24 09:31:44 PDT
<rdar://problem/75788772>
Comment 20 EWS 2021-03-24 09:45:16 PDT
Committed r274941: <https://commits.webkit.org/r274941>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 424053 [details].