Bug 168913 - Optimize checkWebRTCAvailability
Summary: Optimize checkWebRTCAvailability
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-27 08:44 PST by Alex Christensen
Modified: 2017-03-03 14:00 PST (History)
3 users (show)

See Also:


Attachments
Patch (1.96 KB, patch)
2017-02-27 08:47 PST, Alex Christensen
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.