Bug 168913

Summary: Optimize checkWebRTCAvailability
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, jonlee, mitz
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=169147
Attachments:
Description Flags
Patch darin: review+

Description Alex Christensen 2017-02-27 08:44:37 PST
Optimize checkWebRTCAvailability
Comment 1 Alex Christensen 2017-02-27 08:47:03 PST
Created attachment 302843 [details]
Patch
Comment 2 Darin Adler 2017-02-27 09:20:02 PST
Comment on attachment 302843 [details]
Patch

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

> Source/WebKit2/UIProcess/WebPreferences.cpp:213
> +    static bool available = false;
> +    static std::once_flag once;
> +    std::call_once(once, [&]() {
> +        void* libwebrtcLibrary = dlopen("libwebrtc.dylib", RTLD_LAZY);
> +        if (!libwebrtcLibrary) {
> +            available = false;
> +            return;
> +        }
> +        dlclose(libwebrtcLibrary);
> +        available = true;
> +    });
> +    return available;

Does this need to be called from arbitrary threads? If not, then I suggest just using global variable initialization rather than call_once.

    static bool available = [] {
        auto library = dlopen("libwebrtc.dylib", RTLD_LAZY);
        if (!library)
            return false;
        dlclose(library);
        return true;
    }();
    return available;

Fewer lines of code, also slightly more efficient.
Comment 3 Alex Christensen 2017-02-27 09:23:57 PST
http://trac.webkit.org/r213074
Comment 4 mitz 2017-02-27 09:33:45 PST
This check can be implemented by null-checking any of the symbols known to be exported from the dylib, which is a single branch. An implementation that involves a function call still seems unoptimal.
Comment 5 Darin Adler 2017-02-28 16:59:12 PST
(In reply to comment #4)
> This check can be implemented by null-checking any of the symbols known to
> be exported from the dylib, which is a single branch. An implementation that
> involves a function call still seems unoptimal.

We should do that instead!
Comment 6 Jon Lee 2017-03-03 14:00:29 PST
Filed follow-up bug 169147.