RESOLVED FIXED270136
AX: Avoid work in BitmapImage::canAnimate if animation controls are disabled
https://bugs.webkit.org/show_bug.cgi?id=270136
Summary AX: Avoid work in BitmapImage::canAnimate if animation controls are disabled
Joshua Hoffman
Reported 2024-02-26 17:04:22 PST
If a user does not have animation controls enabled, there is no need to do this excess work. <rdar://109646792>
Attachments
Patch (5.12 KB, patch)
2024-02-26 17:17 PST, Joshua Hoffman
no flags
Patch (10.20 KB, patch)
2024-02-27 21:42 PST, Joshua Hoffman
no flags
Patch (11.16 KB, patch)
2024-02-29 09:04 PST, Joshua Hoffman
no flags
Patch (11.16 KB, patch)
2024-02-29 09:51 PST, Joshua Hoffman
no flags
Patch (11.23 KB, patch)
2024-02-29 09:59 PST, Joshua Hoffman
no flags
Patch (12.96 KB, patch)
2024-02-29 15:34 PST, Joshua Hoffman
no flags
Radar WebKit Bug Importer
Comment 1 2024-02-26 17:04:34 PST
Joshua Hoffman
Comment 2 2024-02-26 17:04:49 PST
Joshua Hoffman
Comment 3 2024-02-26 17:17:16 PST
Simon Fraser (smfr)
Comment 4 2024-02-26 17:19:27 PST
Comment on attachment 470059 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470059&action=review > Source/WebCore/page/Page.cpp:2254 > + Image::setSystemAllowsAnimationControls(isAllowed); This is setting process-wide state, but you can have more than one Page in a WebProcess.
Tyler Wilcock
Comment 5 2024-02-26 17:21:25 PST
Comment on attachment 470059 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470059&action=review > Source/WebCore/platform/graphics/BitmapImage.cpp:343 > + return repetitionCount() && !m_animationFinished && (!Image::systemAllowsAnimationControls() || imageObserver()->allowsAnimation(*this)); Do we still want to null-check imageObserver()?
Tyler Wilcock
Comment 6 2024-02-26 17:46:16 PST
Comment on attachment 470059 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470059&action=review > Source/WebCore/loader/cache/CachedImage.cpp:744 > + if (!Image::systemAllowsAnimationControls()) Might be nice to have a comment explaining that CachedImageClient::allowsAnimation() will only ever return false when `systemAllowsAnimationControls`, so this is a fast-path exit to avoid an unnecessary CachedResourceClientWalker walk?
Joshua Hoffman
Comment 7 2024-02-26 18:47:34 PST
Comment on attachment 470059 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470059&action=review >> Source/WebCore/page/Page.cpp:2254 >> + Image::setSystemAllowsAnimationControls(isAllowed); > > This is setting process-wide state, but you can have more than one Page in a WebProcess. That should be fine since we don't enable animation controls per-page. But, I can move this call to the process-level to make that clear.
Joshua Hoffman
Comment 8 2024-02-26 18:48:19 PST
Comment on attachment 470059 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470059&action=review >> Source/WebCore/loader/cache/CachedImage.cpp:744 >> + if (!Image::systemAllowsAnimationControls()) > > Might be nice to have a comment explaining that CachedImageClient::allowsAnimation() will only ever return false when `systemAllowsAnimationControls`, so this is a fast-path exit to avoid an unnecessary CachedResourceClientWalker walk? Good idea, will do! >> Source/WebCore/platform/graphics/BitmapImage.cpp:343 >> + return repetitionCount() && !m_animationFinished && (!Image::systemAllowsAnimationControls() || imageObserver()->allowsAnimation(*this)); > > Do we still want to null-check imageObserver()? Yeah, I inadvertently removed that when refactoring. Will add it back in.
Joshua Hoffman
Comment 9 2024-02-27 21:42:13 PST
Joshua Hoffman
Comment 10 2024-02-27 21:48:17 PST
Updated the patch to set the Image::systemAllowsAnimationControls global from WebProcess, rather than the page, because this setting is per-process. This allows us to remove what we were doing prior with Page::systemAllowsAnimationControl, and have callers to that just call the static method on Image instead.
Tyler Wilcock
Comment 11 2024-02-28 18:19:53 PST
Comment on attachment 470083 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470083&action=review Those api-ios test failures look relevant to this patch > COMMIT_MESSAGE:8 > +Before this patch, the expensive work that happens in BitmapImage::canAnimate would still occur > +in two unnecessary cases: (1) if the image has a single-frame and (2) if image animation controls "Before this patch, the expensive work that happens in BitmapImage::canAnimate would unnecessarily occur in two cases: ..." ? Might be a bit more succinct. > Source/WebCore/loader/cache/CachedImage.cpp:481 > + // *::allowsAnimation can only return false when > + // systemAllowsAnimationControls == true, so this prevents unnecessary work > + // by exiting early. Not a huge deal, but IMO this comment should take up 2 lines, with the first line being longer or equal length to the subsequent one.
Joshua Hoffman
Comment 12 2024-02-29 09:04:40 PST
Joshua Hoffman
Comment 13 2024-02-29 09:07:13 PST
(In reply to Tyler Wilcock from comment #11) > Comment on attachment 470083 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=470083&action=review > > Those api-ios test failures look relevant to this patch Ah yep—since we don't actually perform AX preference changes in layout tests, we were never setting Image::systemAllowsAnimationControls. Fixed this so that we also set it in the Internals method we invoke in the tests. > > COMMIT_MESSAGE:8 > > +Before this patch, the expensive work that happens in BitmapImage::canAnimate would still occur > > +in two unnecessary cases: (1) if the image has a single-frame and (2) if image animation controls > > "Before this patch, the expensive work that happens in > BitmapImage::canAnimate would unnecessarily occur in two cases: ..." ? Might > be a bit more succinct. > > > Source/WebCore/loader/cache/CachedImage.cpp:481 > > + // *::allowsAnimation can only return false when > > + // systemAllowsAnimationControls == true, so this prevents unnecessary work > > + // by exiting early. > > Not a huge deal, but IMO this comment should take up 2 lines, with the first > line being longer or equal length to the subsequent one. Addressed both of these, thank you!
Tyler Wilcock
Comment 14 2024-02-29 09:11:02 PST
Comment on attachment 470098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470098&action=review > Source/WebCore/platform/graphics/Image.h:190 > + WEBCORE_EXPORT static bool gSystemAllowsAnimationControls; Does this need to be WEBCORE_EXPORT? > Source/WebCore/testing/Internals.cpp:1127 > + // We need to set this here to mimic the behavior for the AX preference changing "the behavior of the AX preference changing" rather than "the behavior for the AX preference changing" ?
Joshua Hoffman
Comment 15 2024-02-29 09:50:26 PST
Comment on attachment 470098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=470098&action=review >> Source/WebCore/platform/graphics/Image.h:190 >> + WEBCORE_EXPORT static bool gSystemAllowsAnimationControls; > > Does this need to be WEBCORE_EXPORT? Nope, apologies! will remove.... >> Source/WebCore/testing/Internals.cpp:1127 >> + // We need to set this here to mimic the behavior for the AX preference changing > > "the behavior of the AX preference changing" rather than "the behavior for the AX preference changing" > > ? Changed!
Joshua Hoffman
Comment 16 2024-02-29 09:51:04 PST
Joshua Hoffman
Comment 17 2024-02-29 09:59:23 PST
Joshua Hoffman
Comment 18 2024-02-29 15:34:55 PST
EWS
Comment 19 2024-03-01 12:11:55 PST
Committed 275563@main (1d7be2a5f983): <https://commits.webkit.org/275563@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 470106 [details].
Note You need to log in before you can comment on or make changes to this bug.