Bug 235664 - ImageAnalysisQueue should prioritize elements that intersect the visible viewport
Summary: ImageAnalysisQueue should prioritize elements that intersect the visible view...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-26 12:22 PST by Wenson Hsieh
Modified: 2022-01-27 11:56 PST (History)
8 users (show)

See Also:


Attachments
For EWS (20.32 KB, patch)
2022-01-26 18:38 PST, Wenson Hsieh
darin: review+
Details | Formatted Diff | Diff
Patch for landing (6.29 KB, patch)
2022-01-27 10:38 PST, Wenson Hsieh
wenson_hsieh: commit-queue+
Details | Formatted Diff | Diff
Patch for landing (20.17 KB, patch)
2022-01-27 10:45 PST, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2022-01-26 12:22:05 PST
.
Comment 1 Wenson Hsieh 2022-01-26 18:38:59 PST
Created attachment 450092 [details]
For EWS
Comment 2 Radar WebKit Bug Importer 2022-01-27 07:18:52 PST
<rdar://problem/88131827>
Comment 3 Darin Adler 2022-01-27 07:54:25 PST
Comment on attachment 450092 [details]
For EWS

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

> Source/WebCore/page/ImageAnalysisQueue.h:65
> +    inline static bool isHigherPriority(const Task&, const Task&);
> +    inline unsigned nextTaskNumber();

I don’t think either of these "inline" keywords are needed or helpful.

> Source/WebCore/page/ImageAnalysisQueue.h:76
> +inline bool ImageAnalysisQueue::isHigherPriority(const ImageAnalysisQueue::Task& left, const ImageAnalysisQueue::Task& right)

Can just write Task for the argument types here without the class prefix, since these are inside the function definition.

Once we can use C++20 comparison, this would be better written as an ordering function rather than a "isHigher" function, maybe with the name orderingByPriority, although that doesn't make it clear what the secondary sort would be. I find the name isHigherPriority ambiguous for a function that takes two arguments.

> Tools/TestWebKitAPI/cocoa/ImageAnalysisTestingUtilities.mm:158
> +    RetainPtr<NSURL> _imageURL;
> +    RetainPtr<NSURL> _pageURL;

In tests it seems we can/should use ARC rather than relying on RetainPtr for Objectve-C object lifetimes. Future is ARC. WebKit non-ARC code is just a legacy we’ll eventually have to overcome/revise. Maybe we can start doing this a source file at a time in the rest of WebKit too.
Comment 4 Wenson Hsieh 2022-01-27 09:49:07 PST
Comment on attachment 450092 [details]
For EWS

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

Thanks for the review!

>> Source/WebCore/page/ImageAnalysisQueue.h:65
>> +    inline unsigned nextTaskNumber();
> 
> I don’t think either of these "inline" keywords are needed or helpful.

Good point — removed!

>> Source/WebCore/page/ImageAnalysisQueue.h:76
>> +inline bool ImageAnalysisQueue::isHigherPriority(const ImageAnalysisQueue::Task& left, const ImageAnalysisQueue::Task& right)
> 
> Can just write Task for the argument types here without the class prefix, since these are inside the function definition.
> 
> Once we can use C++20 comparison, this would be better written as an ordering function rather than a "isHigher" function, maybe with the name orderingByPriority, although that doesn't make it clear what the secondary sort would be. I find the name isHigherPriority ambiguous for a function that takes two arguments.

Changed from ImageAnalysisQueue::Task => Task.

Perhaps for now, I can rename the function (and its arguments) for clarity — I was thinking something like `isHigherPriorityThanOtherTask(const Task& task, const Task& other)`, which would make it more clear which direction the comparison goes.

>> Tools/TestWebKitAPI/cocoa/ImageAnalysisTestingUtilities.mm:158
>> +    RetainPtr<NSURL> _pageURL;
> 
> In tests it seems we can/should use ARC rather than relying on RetainPtr for Objectve-C object lifetimes. Future is ARC. WebKit non-ARC code is just a legacy we’ll eventually have to overcome/revise. Maybe we can start doing this a source file at a time in the rest of WebKit too.

Got it. Yeah, ideally these would not use MRC, but I think it's tricky in this case because `ImageAnalysisTestingUtilities.mm` is a unified source, so I don't think we can easily mark the file as ARC (without opting out of unified sources, that is). This makes me wonder if we should adjust the way we unify sources, such that we can unify all ARC-enabled source files together (separately from non-ARC files).

If you prefer, I can `@no-unify` this file and add `-fobjc-arc` to this file; otherwise, I'll keep it as-is for now, if that's okay.
Comment 5 Darin Adler 2022-01-27 09:55:46 PST
Comment on attachment 450092 [details]
For EWS

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

>>> Source/WebCore/page/ImageAnalysisQueue.h:76
>>> +inline bool ImageAnalysisQueue::isHigherPriority(const ImageAnalysisQueue::Task& left, const ImageAnalysisQueue::Task& right)
>> 
>> Can just write Task for the argument types here without the class prefix, since these are inside the function definition.
>> 
>> Once we can use C++20 comparison, this would be better written as an ordering function rather than a "isHigher" function, maybe with the name orderingByPriority, although that doesn't make it clear what the secondary sort would be. I find the name isHigherPriority ambiguous for a function that takes two arguments.
> 
> Changed from ImageAnalysisQueue::Task => Task.
> 
> Perhaps for now, I can rename the function (and its arguments) for clarity — I was thinking something like `isHigherPriorityThanOtherTask(const Task& task, const Task& other)`, which would make it more clear which direction the comparison goes.

I would use a name like firstIsHigherPriority.
Comment 6 Darin Adler 2022-01-27 09:57:22 PST
Comment on attachment 450092 [details]
For EWS

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

>>> Tools/TestWebKitAPI/cocoa/ImageAnalysisTestingUtilities.mm:158
>>> +    RetainPtr<NSURL> _pageURL;
>> 
>> In tests it seems we can/should use ARC rather than relying on RetainPtr for Objectve-C object lifetimes. Future is ARC. WebKit non-ARC code is just a legacy we’ll eventually have to overcome/revise. Maybe we can start doing this a source file at a time in the rest of WebKit too.
> 
> Got it. Yeah, ideally these would not use MRC, but I think it's tricky in this case because `ImageAnalysisTestingUtilities.mm` is a unified source, so I don't think we can easily mark the file as ARC (without opting out of unified sources, that is). This makes me wonder if we should adjust the way we unify sources, such that we can unify all ARC-enabled source files together (separately from non-ARC files).
> 
> If you prefer, I can `@no-unify` this file and add `-fobjc-arc` to this file; otherwise, I'll keep it as-is for now, if that's okay.

We need to start turning the tide and not just accumulate more and more non-ARC code.

Not by doing @no-unify, but my making ARC normal and non-ARC the exception in this project. It’s the non-ARC that will need something like @no-unify. But I understand if you can’t be the one to do it with this one source file.

By the way, I think we can convert all our tests and it won’t even be a challenging project. Converting WebKit itself is far more difficult.
Comment 7 Wenson Hsieh 2022-01-27 10:13:09 PST
Comment on attachment 450092 [details]
For EWS

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

>>>> Source/WebCore/page/ImageAnalysisQueue.h:76
>>>> +inline bool ImageAnalysisQueue::isHigherPriority(const ImageAnalysisQueue::Task& left, const ImageAnalysisQueue::Task& right)
>>> 
>>> Can just write Task for the argument types here without the class prefix, since these are inside the function definition.
>>> 
>>> Once we can use C++20 comparison, this would be better written as an ordering function rather than a "isHigher" function, maybe with the name orderingByPriority, although that doesn't make it clear what the secondary sort would be. I find the name isHigherPriority ambiguous for a function that takes two arguments.
>> 
>> Changed from ImageAnalysisQueue::Task => Task.
>> 
>> Perhaps for now, I can rename the function (and its arguments) for clarity — I was thinking something like `isHigherPriorityThanOtherTask(const Task& task, const Task& other)`, which would make it more clear which direction the comparison goes.
> 
> I would use a name like firstIsHigherPriority.

Sounds good — I'll go with firstIsHigherPriority(first, second).

>>>> Tools/TestWebKitAPI/cocoa/ImageAnalysisTestingUtilities.mm:158
>>>> +    RetainPtr<NSURL> _pageURL;
>>> 
>>> In tests it seems we can/should use ARC rather than relying on RetainPtr for Objectve-C object lifetimes. Future is ARC. WebKit non-ARC code is just a legacy we’ll eventually have to overcome/revise. Maybe we can start doing this a source file at a time in the rest of WebKit too.
>> 
>> Got it. Yeah, ideally these would not use MRC, but I think it's tricky in this case because `ImageAnalysisTestingUtilities.mm` is a unified source, so I don't think we can easily mark the file as ARC (without opting out of unified sources, that is). This makes me wonder if we should adjust the way we unify sources, such that we can unify all ARC-enabled source files together (separately from non-ARC files).
>> 
>> If you prefer, I can `@no-unify` this file and add `-fobjc-arc` to this file; otherwise, I'll keep it as-is for now, if that's okay.
> 
> We need to start turning the tide and not just accumulate more and more non-ARC code.
> 
> Not by doing @no-unify, but my making ARC normal and non-ARC the exception in this project. It’s the non-ARC that will need something like @no-unify. But I understand if you can’t be the one to do it with this one source file.
> 
> By the way, I think we can convert all our tests and it won’t even be a challenging project. Converting WebKit itself is far more difficult.

👍🏻 I'll keep this part of the patch as-is, then — I filed https://bugs.webkit.org/show_bug.cgi?id=235722 to track enabling ARC in TestWebKitAPI.

From a cursory glance, there aren't a whole lot of manual -release/-retains, so (as you mentioned) it should be relatively straightforward! I'll take a look later.
Comment 8 Wenson Hsieh 2022-01-27 10:38:35 PST
Created attachment 450156 [details]
Patch for landing
Comment 9 Darin Adler 2022-01-27 10:40:50 PST
Comment on attachment 450156 [details]
Patch for landing

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

> Source/WebCore/page/ImageAnalysisQueue.h:87
> +inline unsigned ImageAnalysisQueue::nextTaskNumber()
> +{
> +    return ++m_currentTaskNumber;
> +}

Just realized this function can be in the .cpp file. Sure, it’s inline, but all callers are also in the .cpp file.
Comment 10 Darin Adler 2022-01-27 10:41:17 PST
Comment on attachment 450156 [details]
Patch for landing

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

>> Source/WebCore/page/ImageAnalysisQueue.h:87
>> +}
> 
> Just realized this function can be in the .cpp file. Sure, it’s inline, but all callers are also in the .cpp file.

Or, it’s so short it could just be up above:

    unsigned nextTaskNumber() { return ++m_currentTaskNumber; }
Comment 11 Wenson Hsieh 2022-01-27 10:43:38 PST
(In reply to Darin Adler from comment #10)
> Comment on attachment 450156 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=450156&action=review
> 
> >> Source/WebCore/page/ImageAnalysisQueue.h:87
> >> +}
> > 
> > Just realized this function can be in the .cpp file. Sure, it’s inline, but all callers are also in the .cpp file.
> 
> Or, it’s so short it could just be up above:
> 
>     unsigned nextTaskNumber() { return ++m_currentTaskNumber; }

Sounds good — will move it above!
Comment 12 Wenson Hsieh 2022-01-27 10:45:00 PST
Created attachment 450158 [details]
Patch for landing
Comment 13 EWS 2022-01-27 11:56:34 PST
Committed r288690 (246489@main): <https://commits.webkit.org/246489@main>

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