Closed Bug 1490044 Opened 6 years ago Closed 5 years ago

Use StaticPrefs directly in WebIDL

Categories

(Core :: DOM: Core & HTML, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox69 --- fixed

People

(Reporter: baku, Assigned: peterv)

Details

Attachments

(8 files)

StaticPrefs are nice because they are (if marked as atomic) thread-safe.
Currently, for many APIs, we use [Func="foo"] just to check a pref, in thread-safe way. DOMPrefs.h does this for several DOM preferences.

Would be nice to have [StaticPref="foo"] attribute in our WebIDL parser/code generator and get rid of DOMPrefs.
Assignee: nobody → amarchesini
Attachment #9007807 - Flags: review?(peterv)
Attachment #9007808 - Flags: review?(peterv)
Attachment #9007824 - Flags: review?(peterv)
Priority: -- → P2
Comment on attachment 9007807 [details] [diff] [review]
part 1 - [StaticPref="foo"]

Review of attachment 9007807 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/bindings/Codegen.py
@@ +1229,5 @@
>              # getExtendedAttribute() returns a list, extract the entry.
>              funcList = desc.interface.getExtendedAttribute("Func")
>              if funcList is not None:
>                  addHeaderForFunc(funcList[0], desc)
> +            # getExtendedAttribute() returns a list, extract the entry.

Drop the comment, you're not extracting the entry.

@@ +2145,5 @@
>                       prefCacheTemplate % (name, len(prefableSpecs))))
> +            # StaticPref converted to method call.
> +            staticPrefMethod = "nullptr";
> +            if condition.staticPref is not None:
> +                staticPrefMethod = "StaticPrefs::%s" % condition.staticPref.replace(".", "_")

This will need to be clearly documented (replacing . with _), because afaict users of the VARCACHE_PREF macro can choose to use whatever id they want.

::: dom/bindings/DOMJSClass.h
@@ +145,5 @@
>    // because it will change at runtime if the corresponding pref is changed.
>    bool enabled;
>  
> +  // Static pref method.
> +  bool (*staticPref)();

Can we make this a const pointer?
Attachment #9007807 - Flags: review?(peterv) → review+
Attachment #9007808 - Flags: review?(peterv) → review+
Bz and I talked a bit about this, and he raised some concerns:

1) The overhead of calling the function call
2) The binary size hit of the function pointer (made worse by the unfortunate positioning of the pointer in between bools)
3) More relocations

1 and 3 are not problems in particular with the ones you convert here (since they used Func before), but 2 is. However, if we plan to move everything to StaticPrefs in the future, then it might make more sense to do the whole conversion at once here.

For the binary size hit, bz proposed making an array of function pointers to StaticPrefs' functions and storing an index in PrefableDisablers. If we take some bits from nonExposedGlobals and secureContext (which can use 1 bit), and drop the |enabled| bool, we have plenty of space to store such an index. The hope is that the array of function pointers will be less of a size hit and require fewer relocations. Also, because we remove the non-const |enabled| bool we can make the PrefableDisablers arrays const.

After talking to bz I think I agree with his concerns. Would you be up for doing these changes? I can try to take over if not.
Flags: needinfo?(amarchesini)

After talking to bz I think I agree with his concerns. Would you be up for
doing these changes? I can try to take over if not.

Peter, I'll not be able to work on this. Do you have cycles?

Flags: needinfo?(amarchesini)
Component: DOM → DOM: Core & HTML

Depends on D33509

Assignee: amarchesini → peterv
Pushed by pvanderbeken@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1091aed2035c
Move all prefs used in WebIDL to StaticPrefs. r=bzbarsky
https://hg.mozilla.org/integration/autoland/rev/7526d2cbe12d
Convert WebIDL pref disablers to use StaticPrefs. r=bzbarsky
https://hg.mozilla.org/integration/autoland/rev/f5f71d6a5abc
Remove DOMPrefs MACRO for WebIDL support. r=bzbarsky
https://hg.mozilla.org/integration/autoland/rev/3e6dc353ad6e
Remove DOMPrefs. r=bzbarsky

uhm,
0:03.54 In file included from /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dom/bindings/UnifiedBindings1.cpp:2:
0:03.54 /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dom/bindings/AudioWorkletBinding.cpp:4:10: fatal error: 'DOMPrefs.h' file not found
0:03.54 #include "DOMPrefs.h"
0:03.54 ^~~~~~~~~~~~
0:04.40 In file included from /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dom/bindings/UnifiedBindings0.cpp:2:
0:04.40 /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dom/bindings/APZTestDataBinding.cpp:5:10: fatal error: 'DOMPrefs.h' file not found
0:04.40 #include "DOMPrefs.h"
0:04.40 ^~~~~~~~~~~~

tested on:
changeset: 478901:b3a69dff7e25
tag: tip
date: Thu Jun 13 20:21:46 2019 +0000
summary: Bug 1558485 - Turn on ESLint for all of dom/ disabling most of the failing rules. r=smaug

Looks like it comes from:
dom/bindings/Codegen.py:14705: bindingHeaders["DOMPrefs.h"] = descriptors

Attached patch le.patchSplinter Review

yep that fixed it(aka removed all 124 includes from obj-x86_64-pc-linux-gnu/dom/bindings/)
(now, it's still compiling so unsure if it still finishes successfully, but assuming it will;-) )

ok my bad, turns out I was already apply a patch earlier which added it! hence why removing it was needed:

from https://github.com/bn0785ac/firefox-beta/blob/master/fix.patch
via https://bugzilla.mozilla.org/show_bug.cgi?id=1433562#c3

Attachment #9007824 - Flags: review?(peterv)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: