Skip to content

rules/RuleBook: Optimize saving discarded rules to config

Ismael Asensio requested to merge work/iasensio/rules-book-integration into master

After porting to KConfigXT settings some time ago, there was still an inefficient and error-prone codepath between the RuleBook (which keeps the runtime list of Rules) and the RuleBookSettings (responsible for config reads and saves), in the form of the setRules() method.

Before

Whenever the RuleBook needed to synchronize its state to config, either on kwin exit, or to discard a temporary rule ("Apply Now", "Force Temporarily") it would:

  • create a new RuleBookSettings object, which loads the full config
  • transfer the whole runtime set of rules via setRules(): this goes through every one of the rules in the settings, rewritting them even when most of them haven't changed, and not preserving config groups
  • save to file

After

We can eliminate the setRules() codepath, reducing unnecessary runtime process and file access operations, and instead:

  • Keep track of the config id in the Rules objects
  • Keep a single RuleBookSettings object as a member
  • Modify or delete the discarded rules settings directly
  • Save when necessary

This also fixes two bugs/pitfalls of the previous solution (there are no explicit BRs but it has been mentioned a couple times on Matrix):

  • the config group id for each rule is now preserved instead of creating new ones
  • no leftovers on the config file for the discarded groups and entries ( BUG: 446381 | FIXED-IN: 6.1)

Setting custom configs for the integration tests still works unchanged.

TESTING TIPS :

  • Integration test keeps working (they check for "Apply Now" and "Force Temporarily" properties)
  • kwin should be restarted first, so the previous running code don't override the rules config
  • Open ~/.config/kwinrulesrc in an editor to watch for changes
  • Create two new rules:
    • one with a temporary policy (ex. "Force Temporarily")
    • one with a permanent policy (ex. "Force")
  • Open a window that triggers the rule:
    • The group for the temporary rule gets removed from the config file
    • The group for the permanent rule stays with an UUID group name
  • Restart kwin -> No new writes to the config file
Edited by Ismael Asensio

Merge request reports

Loading