Bug 218289

Summary: [iOS] Link Contacts.framework during build
Product: WebKit Reporter: Aditya Keerthi <akeerthi>
Component: WebKit Misc.Assignee: Aditya Keerthi <akeerthi>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, ggaren, thorton, tsavell, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=218314
Attachments:
Description Flags
Patch
none
Patch for landing.
none
Patch
aestes: review+
Patch for landing none

Description Aditya Keerthi 2020-10-28 09:16:42 PDT
...
Comment 1 Aditya Keerthi 2020-10-28 09:18:21 PDT
Created attachment 412533 [details]
Patch
Comment 2 Geoffrey Garen 2020-10-28 09:26:48 PDT
Comment on attachment 412533 [details]
Patch

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

r=me

> Source/WebKit/ChangeLog:4
> +        [Cocoa] Remove soft linking of Contacts.framework
> +        https://bugs.webkit.org/show_bug.cgi?id=218289

Nice!

> Source/WebKit/ChangeLog:9
> +        Since Contacts.framework does not depend on WebKit and soft linking is
> +        discouraged, WebKit should link Contacts.framework normally.

This is a complex topic that few people understand, so I think a slightly more detailed rationale is warranted in this ChangeLog.

Soft linking has a performance cost because it uses a function call (dlopen) at runtime, and that requires running the linker at runtime, and running the linker has a cost.

Weak linking avoids this performance cost because weak linking declares your linkage at build time, which enables running the linker at build time or update time or install time, avoiding the runtime cost.
Comment 3 Aditya Keerthi 2020-10-28 09:52:22 PDT
Created attachment 412538 [details]
Patch for landing.
Comment 4 Aditya Keerthi 2020-10-28 09:54:07 PDT
(In reply to Geoffrey Garen from comment #2)
> Comment on attachment 412533 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=412533&action=review
> 
> r=me

Thank you for the review!
 
> > Source/WebKit/ChangeLog:4
> > +        [Cocoa] Remove soft linking of Contacts.framework
> > +        https://bugs.webkit.org/show_bug.cgi?id=218289
> 
> Nice!
> 
> > Source/WebKit/ChangeLog:9
> > +        Since Contacts.framework does not depend on WebKit and soft linking is
> > +        discouraged, WebKit should link Contacts.framework normally.
> 
> This is a complex topic that few people understand, so I think a slightly
> more detailed rationale is warranted in this ChangeLog.
> 
> Soft linking has a performance cost because it uses a function call (dlopen)
> at runtime, and that requires running the linker at runtime, and running the
> linker has a cost.
> 
> Weak linking avoids this performance cost because weak linking declares your
> linkage at build time, which enables running the linker at build time or
> update time or install time, avoiding the runtime cost.

I've added a similar description to the new Changelog :)
Comment 5 EWS 2020-10-28 10:41:17 PDT
Committed r269109: <https://trac.webkit.org/changeset/269109>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 412538 [details].
Comment 6 Radar WebKit Bug Importer 2020-10-28 10:42:20 PDT
<rdar://problem/70770410>
Comment 7 Geoffrey Garen 2020-10-28 11:17:13 PDT
Comment on attachment 412538 [details]
Patch for landing.

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

> Source/WebKit/ChangeLog:19
> +        Since Contacts.framework does not depend on WebKit and soft linking is
> +        discouraged, WebKit should link Contacts.framework normally.
> +
> +        Soft linking requires running the linker at runtime, leading to an
> +        unwanted performance cost. By normally linking (on iOS) and weak linking
> +        (on macOS), the linkage is declared at build time, which enables running
> +        the linker at build/update/install time and avoiding the runtime cost.
> +
> +        * Configurations/WebKit.xcconfig:
> +
> +        On macOS, weak link the framework since Contacts.framework is not
> +        available on the Base System.

Perfect!
Comment 8 Truitt Savell 2020-10-28 16:25:14 PDT
It looks like the changes in https://trac.webkit.org/changeset/269109/webkit

broke TestWebKitAPI.ContentFiltering.LazilyLoadPlatformFrameworks

History:
https://results.webkit.org/?suite=api-tests&test=TestWebKitAPI.ContentFiltering.LazilyLoadPlatformFrameworks

diff:
Failed

    TestWebKitAPI.ContentFiltering.LazilyLoadPlatformFrameworks
        
        /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:374
        Expected equality of these values:
          static_cast<bool>(networkExtensionShouldBeLoaded)
            Which is: false
          static_cast<bool>(networkExtensionLoaded)
            Which is: true
        
        
        /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:374
        Expected equality of these values:
          static_cast<bool>(networkExtensionShouldBeLoaded)
            Which is: false
          static_cast<bool>(networkExtensionLoaded)
            Which is: true
        
        
        /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:374
        Expected equality of these values:
          static_cast<bool>(networkExtensionShouldBeLoaded)
            Which is: false
          static_cast<bool>(networkExtensionLoaded)
            Which is: true
        
        
        /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:374
        Expected equality of these values:
          static_cast<bool>(networkExtensionShouldBeLoaded)
            Which is: false
          static_cast<bool>(networkExtensionLoaded)
            Which is: true
        
        
        /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentFiltering.mm:374
        Expected equality of these values:
          static_cast<bool>(networkExtensionShouldBeLoaded)
            Which is: false
          static_cast<bool>(networkExtensionLoaded)
            Which is: true
Comment 9 Tim Horton 2020-10-28 17:10:23 PDT
(In reply to Truitt Savell from comment #8)
> It looks like the changes in https://trac.webkit.org/changeset/269109/webkit
> 
> broke TestWebKitAPI.ContentFiltering.LazilyLoadPlatformFrameworks
> 
> History:
> https://results.webkit.org/?suite=api-tests&test=TestWebKitAPI.
> ContentFiltering.LazilyLoadPlatformFrameworks
> 
> diff:
> Failed
> 
>     TestWebKitAPI.ContentFiltering.LazilyLoadPlatformFrameworks
>         
>        
> /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/ContentFiltering.mm:374
>         Expected equality of these values:
>           static_cast<bool>(networkExtensionShouldBeLoaded)
>             Which is: false
>           static_cast<bool>(networkExtensionLoaded)
>             Which is: true
>         
>         
>        
> /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/ContentFiltering.mm:374
>         Expected equality of these values:
>           static_cast<bool>(networkExtensionShouldBeLoaded)
>             Which is: false
>           static_cast<bool>(networkExtensionLoaded)
>             Which is: true
>         
>         
>        
> /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/ContentFiltering.mm:374
>         Expected equality of these values:
>           static_cast<bool>(networkExtensionShouldBeLoaded)
>             Which is: false
>           static_cast<bool>(networkExtensionLoaded)
>             Which is: true
>         
>         
>        
> /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/ContentFiltering.mm:374
>         Expected equality of these values:
>           static_cast<bool>(networkExtensionShouldBeLoaded)
>             Which is: false
>           static_cast<bool>(networkExtensionLoaded)
>             Which is: true
>         
>         
>        
> /Volumes/Data/slave/catalina-release/build/Tools/TestWebKitAPI/Tests/
> WebKitCocoa/ContentFiltering.mm:374
>         Expected equality of these values:
>           static_cast<bool>(networkExtensionShouldBeLoaded)
>             Which is: false
>           static_cast<bool>(networkExtensionLoaded)
>             Which is: true

Heh, that's kind of a silly test. Contacts must be dragging in NE, but that's OK.
Comment 10 Ryan Haddad 2020-10-29 10:47:34 PDT
Reverted r269109 for reason:

Introduced dependency cycle

Committed r269154: <https://trac.webkit.org/changeset/269154>
Comment 11 Aditya Keerthi 2020-10-29 17:55:36 PDT
Created attachment 412700 [details]
Patch
Comment 12 Andy Estes 2020-10-30 10:38:21 PDT
Comment on attachment 412700 [details]
Patch

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

> Source/WebKit/Platform/cocoa/PaymentAuthorizationPresenter.mm:42
> +// on macOS, or when Contacts can be upward linked.

Are there radars that track either of these changes? We should link to them here so we know when it's safe to stop soft-linking on macOS.
Comment 13 Aditya Keerthi 2020-10-30 11:44:39 PDT
Created attachment 412781 [details]
Patch for landing
Comment 14 Aditya Keerthi 2020-10-30 11:45:07 PDT
Comment on attachment 412781 [details]
Patch for landing

Added links to radars.
Comment 15 EWS 2020-11-02 11:46:32 PST
Committed r269263: <https://trac.webkit.org/changeset/269263>

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