Repository navigation
#8539 Config preferences backend restructure - #22923
Conversation
|
Heads up! This PR modifies the following files:
|
|
This looks like an improvement to me! @jdm, I believe you had some plans around config, is this PR in line with what you were thinking? |
|
@asajeffrey There is some discussion with @jdm on the original issue #8539. In the end, I was able to make both the static and key-based interface mutable. |
|
☔ The latest upstream changes (presumably #22940) made this pull request unmergeable. Please resolve the merge conflicts. |
89d7382 to
08e3c40
Compare
|
☔ The latest upstream changes (presumably #22939) made this pull request unmergeable. Please resolve the merge conflicts. |
08e3c40 to
2a1e5d8
Compare
|
☔ The latest upstream changes (presumably #22945) made this pull request unmergeable. Please resolve the merge conflicts. |
2a1e5d8 to
30f2c23
Compare
asajeffrey
left a comment
There was a problem hiding this comment.
Mainly this looks really good! A few questions though...
|
|
||
| pub struct Accessor<P, V> { | ||
| pub getter: Box<Fn(&P) -> V + Sync>, | ||
| pub setter: Box<Fn(&mut P, V) + Sync>, |
There was a problem hiding this comment.
Hmm, this is doing dynamic dispatch. Do we ever access a pref inside a hot loop?
There was a problem hiding this comment.
Yes, prefs are accessed all the time during CSS parsing.
There was a problem hiding this comment.
These accessors are only used for accessing preferences using their string keys. In most places the value is accessed directly from the structs (usually via the get_pref! macro.
There was a problem hiding this comment.
I will take a look at the CSS code to check if it is using the string names.
There was a problem hiding this comment.
I also realise that the accessors are used in every place that a preference is changed. In places where the preference name is statically known, I can actually change that to update the structs directly.
There was a problem hiding this comment.
@asajeffrey With regard to accessing preferences in CSS, I don't follow the Python code generation very well. Are there existing benchmarks for the CSS to make sure that nothing is degraded? I can't see a ./mach command for that.
There was a problem hiding this comment.
I don't think I know of anything else that isn't reloading a page full of stylesheets over and over. In any case, looks like we don't have that many pref-gated properties, so probably not something that should concern us much.
There was a problem hiding this comment.
@emilio can you point me to where some pref-gated CSS properties are implemented?
There was a problem hiding this comment.
Sure, just grep for servo_pref= in components/style/properties. Looks like we have a few of them gated with layout.columns.enabled, and then layout.writing-mode.enabled.
|
I just want to chime in and say that this was clearly more complex than I originally thought, and that I'm impressed by your solution! |
emilio
left a comment
There was a problem hiding this comment.
It is a bit unfortunate to have to pay the cost of locking and arc-cloning to access simple prefs. Ideally bool prefs should be just a relaxed atomic read. Though given this simplifies the API and makes it easy to change it under the hood, it may be worth to land it and improve that as a follow-up...
The existing implementation stores the preferences in a The choice was between locking the entire structure or locking individual preferences, and I went with the simplest one. Since most code can use the macros, as you say, it can be changed under the hood. |
|
Opened new PR for upstreamable changes. Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617. |
|
Transplanted upstreamable changes to existing PR. Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617. |
101eb80 to
675b494
Compare
|
Transplanted upstreamable changes to existing PR. Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617. |
1 similar comment
|
Transplanted upstreamable changes to existing PR. Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617. |
|
📌 Commit 73e47e9 has been approved by |
#8539 Config preferences backend restructure <!-- Please describe your changes on the following line: --> A procedural macro for generating static structures for use as the backend for config preferences, as well a mapping from string names to accessors. Preferences can be accessed and updated via a map-like interface with `String` keys, and now also via a convenience macro: `get_pref!(path.to.pref)`. Various `serde`-compatible field attributes are also supported, including renaming the string keys. This could be useful when changing the backend structure without breaking existing usages. I have added the choice to use `i64` as well as `f64` for storing numbers. As it turns out, none of the existing preferences used non-integer values. Setting a floating point value from a command-line argument requires a decimal point in order to parse correctly. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #8539 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> ----- I have a few outstanding problems or questions: 1. I am unable to get rid of this warning: ``` warning: unnecessary path disambiguator --> components/config/prefs.rs:130:51 | 130 | accessor_type = crate::pref_util::Accessor::<Prefs, crate::pref_util::PrefValue>, | ^^ try removing `::` ``` See: https://stackoverflow.com/questions/54710797/how-to-disable-unnecessary-path-disambiguator-warning 2. Several of the preferences in use were not represented in `prefs.json`. Some of these may be in error, but it is hard to tell. For example `js.offthread_compilation.enabled` vs `js.ion.offthread_compilation.enabled` could be different preferences or could be intended to have the same value. 3. Previously, several pieces of code provided default values when accessing a preference that may not be present. For example: ```Rust let DBL_CLICK_TIMEOUT = Duration::from_millis( PREFS .get("dom.document.dblclick_timeout") .as_u64() .unwrap_or(300), ); ``` Fallback values don't really make sense now and I've added these defaults to `prefs.json`. Does this sound right? 4. I have kept `PrefValue::Missing`, though it doesn't seem very useful any more. An error might be more appropriate now for an incorrect preference key. I've kept this partly because [`webdriver_server` uses it](https://github.com/servo/servo/blob/master/components/webdriver_server/lib.rs#L224). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22923) <!-- Reviewable:end -->
|
💔 Test failed - linux-rel-css |
|
dom.testbinding.preference_value.quote_string_test |
73e47e9 to
8bfd4dc
Compare
|
@jdm I also found |
|
@jdm I've come across some mention of prefs in some Python tests, e.g: https://github.com/servo/servo/blob/master/tests/wpt/web-platform-tests/tools/wptrunner/wptrunner/tests/test_wpttest.py#L14 : I'm not exactly sure what these are doing though, or how to make sure that I've run them properly. Are these trying to set and reset a pref called "a"? |
|
Those are python-only unit tests for wptrunner and don't run against Servo. |
|
@bors-servo r+ |
|
📌 Commit 8bfd4dc has been approved by |
#8539 Config preferences backend restructure <!-- Please describe your changes on the following line: --> A procedural macro for generating static structures for use as the backend for config preferences, as well a mapping from string names to accessors. Preferences can be accessed and updated via a map-like interface with `String` keys, and now also via a convenience macro: `get_pref!(path.to.pref)`. Various `serde`-compatible field attributes are also supported, including renaming the string keys. This could be useful when changing the backend structure without breaking existing usages. I have added the choice to use `i64` as well as `f64` for storing numbers. As it turns out, none of the existing preferences used non-integer values. Setting a floating point value from a command-line argument requires a decimal point in order to parse correctly. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #8539 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> ----- I have a few outstanding problems or questions: 1. I am unable to get rid of this warning: ``` warning: unnecessary path disambiguator --> components/config/prefs.rs:130:51 | 130 | accessor_type = crate::pref_util::Accessor::<Prefs, crate::pref_util::PrefValue>, | ^^ try removing `::` ``` See: https://stackoverflow.com/questions/54710797/how-to-disable-unnecessary-path-disambiguator-warning 2. Several of the preferences in use were not represented in `prefs.json`. Some of these may be in error, but it is hard to tell. For example `js.offthread_compilation.enabled` vs `js.ion.offthread_compilation.enabled` could be different preferences or could be intended to have the same value. 3. Previously, several pieces of code provided default values when accessing a preference that may not be present. For example: ```Rust let DBL_CLICK_TIMEOUT = Duration::from_millis( PREFS .get("dom.document.dblclick_timeout") .as_u64() .unwrap_or(300), ); ``` Fallback values don't really make sense now and I've added these defaults to `prefs.json`. Does this sound right? 4. I have kept `PrefValue::Missing`, though it doesn't seem very useful any more. An error might be more appropriate now for an incorrect preference key. I've kept this partly because [`webdriver_server` uses it](https://github.com/servo/servo/blob/master/components/webdriver_server/lib.rs#L224). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22923) <!-- Reviewable:end -->
|
☀️ Test successful - android-mac, arm32, arm64, linux-rel-css, linux-rel-wpt, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, magicleap, status-taskcluster |
|
Woohoo! Great work, @peterjoel. |
A procedural macro for generating static structures for use as the backend for config preferences, as well a mapping from string names to accessors.
Preferences can be accessed and updated via a map-like interface with
Stringkeys, and now also via a convenience macro:get_pref!(path.to.pref). Variousserde-compatible field attributes are also supported, including renaming the string keys. This could be useful when changing the backend structure without breaking existing usages.I have added the choice to use
i64as well asf64for storing numbers. As it turns out, none of the existing preferences used non-integer values. Setting a floating point value from a command-line argument requires a decimal point in order to parse correctly../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsI have a few outstanding problems or questions:
prefs.json. Some of these may be in error, but it is hard to tell. For examplejs.offthread_compilation.enabledvsjs.ion.offthread_compilation.enabledcould be different preferences or could be intended to have the same value.prefs.json. Does this sound right?PrefValue::Missing, though it doesn't seem very useful any more. An error might be more appropriate now for an incorrect preference key. I've kept this partly becausewebdriver_serveruses it.This change is