Skip to content

#8539 Config preferences backend restructure - #22923

Merged
bors-servo merged 1 commit into
servo:masterfrom
peterjoel:issue_8539_prefs_refactor
Mar 20, 2019
Merged

bors-servo merged 1 commit into
servo:masterfrom
peterjoel:issue_8539_prefs_refactor

Conversation

@peterjoel

@peterjoel peterjoel commented Feb 21, 2019 •

Copy link
Copy Markdown
Contributor

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.


  • There are tests for these changes OR
  • These changes do not require tests because ___

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:
    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.

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @jgraham: components/webdriver_server/lib.rs
  • @emilio: components/style/stylesheets/viewport_rule.rs, components/style/global_style_data.rs, components/style/properties/properties.mako.rs
  • @KiChjang: components/net/filemanager_thread.rs, components/net/lib.rs, components/script/dom/bindings/guard.rs, components/script/dom/htmlmetaelement.rs, components/script/dom/servoparser/mod.rs and 16 more
  • @asajeffrey: components/script/dom/bindings/guard.rs, components/script/dom/htmlmetaelement.rs, components/script/dom/servoparser/mod.rs, components/script/dom/mouseevent.rs, components/script/dom/htmlcanvaselement.rs and 15 more
  • @cbrewster: components/constellation/pipeline.rs, components/constellation/constellation.rs
  • @paulrouget: ports/servo/browser.rs, components/servo/lib.rs, ports/servo/non_android_main.rs, components/constellation/pipeline.rs, components/constellation/constellation.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Feb 21, 2019
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@asajeffrey

Copy link
Copy Markdown
Contributor

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?

@peterjoel

Copy link
Copy Markdown
Contributor Author

@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.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #22940) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Feb 26, 2019
@peterjoel
peterjoel force-pushed the issue_8539_prefs_refactor branch 3 times, most recently from 89d7382 to 08e3c40 Compare February 27, 2019 15:39
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Feb 27, 2019
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #22939) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Feb 27, 2019
@peterjoel
peterjoel force-pushed the issue_8539_prefs_refactor branch from 08e3c40 to 2a1e5d8 Compare February 27, 2019 19:02
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #22945) made this pull request unmergeable. Please resolve the merge conflicts.

@peterjoel
peterjoel force-pushed the issue_8539_prefs_refactor branch from 2a1e5d8 to 30f2c23 Compare February 28, 2019 13:41

@asajeffrey asajeffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly this looks really good! A few questions though...

Comment thread components/config/pref_util.rs Resolved

pub struct Accessor<P, V> {
pub getter: Box<Fn(&P) -> V + Sync>,
pub setter: Box<Fn(&mut P, V) + Sync>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is doing dynamic dispatch. Do we ever access a pref inside a hot loop?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, prefs are accessed all the time during CSS parsing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look at the CSS code to check if it is using the string names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know I'm afraid. @emilio?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilio can you point me to where some pref-gated CSS properties are implemented?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread components/config/pref_util.rs Resolved
Comment thread components/config/prefs.rs Resolved
Comment thread components/config/prefs.rs Resolved
@jdm

jdm commented Feb 28, 2019

Copy link
Copy Markdown
Member

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 emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Comment thread components/config/prefs.rs Resolved
Comment thread components/config/prefs.rs Resolved
@peterjoel

Copy link
Copy Markdown
Contributor Author

@emilio wrote:
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 Arc<RwLock<HashMap<String, Pref>>>, but each Pref also wraps the value in another Arc. Hopefully, this new implementation is at least no worse than that.

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.

Comment thread components/config/opts.rs Resolved
Comment thread components/config/opts.rs Resolved
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Opened new PR for upstreamable changes.

Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617.

Comment thread components/webdriver_server/lib.rs Resolved
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617.

@peterjoel
peterjoel force-pushed the issue_8539_prefs_refactor branch from 101eb80 to 675b494 Compare March 1, 2019 12:11
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617.

1 similar comment
@servo-wpt-sync

Copy link
Copy Markdown
Collaborator

Transplanted upstreamable changes to existing PR.

Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#15617.

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 73e47e9 has been approved by asajeffrey

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 19, 2019
bors-servo pushed a commit that referenced this pull request Mar 19, 2019
#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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 73e47e9 with merge db1685a...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Mar 19, 2019
@jdm

jdm commented Mar 19, 2019

Copy link
Copy Markdown
Member

dom.testbinding.preference_value.quote_string_test

@peterjoel
peterjoel force-pushed the issue_8539_prefs_refactor branch from 73e47e9 to 8bfd4dc Compare March 20, 2019 15:09
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Mar 20, 2019
@peterjoel

Copy link
Copy Markdown
Contributor Author

@jdm I also found browser.display.background-color and browser.display.foreground-color, which I've also added now. Hopefully that's the last.🤞

@peterjoel

Copy link
Copy Markdown
Contributor Author

@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"?

@jdm

jdm commented Mar 20, 2019

Copy link
Copy Markdown
Member

Those are python-only unit tests for wptrunner and don't run against Servo.

@jdm

jdm commented Mar 20, 2019

Copy link
Copy Markdown
Member

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 8bfd4dc has been approved by jdm

@highfive highfive assigned jdm and unassigned asajeffrey Mar 20, 2019
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 20, 2019
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 8bfd4dc with merge 5ec7254...

bors-servo pushed a commit that referenced this pull request Mar 20, 2019
#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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ 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
Approved by: jdm
Pushing 5ec7254 to master...

@bors-servo
bors-servo merged commit 8bfd4dc into servo:master Mar 20, 2019
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 20, 2019
@jdm

jdm commented Mar 20, 2019

Copy link
Copy Markdown
Member

Woohoo! Great work, @peterjoel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace preferences backend with static data structures instead of hashmap

8 participants