[PR #1495] refactor (window): Lazy, Single-pass Evaluation of Window Properties and Efficient Rule Matching #1431

Open
opened 2026-01-05 14:55:15 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/LGUG2Z/komorebi/pull/1495
Author: @JustForFun88
Created: 6/29/2025
Status: 🔄 Open

Base: masterHead: simple_should_act


📝 Commits (6)

  • f9ea220 Stop exposing Ring internals
  • 862a55f Use Arc<str> and WsElementId instead of String
  • 3020684 make serialize and deserialize compact
  • 8cbf024 Make Window internals private.
  • 86b297f Make clippy happy
  • 796e928 Remove should_act, use Window::matches_rule

📊 Changes

41 files changed (+1818 additions, -2177 deletions)

View changed files

📝 komorebi-bar/src/bar.rs (+18 -22)
📝 komorebi-bar/src/main.rs (+13 -23)
📝 komorebi-bar/src/widgets/battery.rs (+1 -1)
📝 komorebi-bar/src/widgets/cpu.rs (+3 -3)
📝 komorebi-bar/src/widgets/date.rs (+1 -1)
📝 komorebi-bar/src/widgets/komorebi.rs (+10 -11)
📝 komorebi-bar/src/widgets/komorebi_layout.rs (+2 -3)
📝 komorebi-bar/src/widgets/memory.rs (+3 -3)
📝 komorebi-bar/src/widgets/mod.rs (+5 -4)
📝 komorebi-bar/src/widgets/network.rs (+2 -2)
📝 komorebi-bar/src/widgets/storage.rs (+2 -2)
📝 komorebi-bar/src/widgets/time.rs (+1 -1)
📝 komorebi-bar/src/widgets/update.rs (+1 -1)
📝 komorebi-gui/src/main.rs (+8 -8)
📝 komorebi/src/animation/prefix.rs (+1 -1)
📝 komorebi/src/border_manager/border.rs (+54 -37)
📝 komorebi/src/border_manager/mod.rs (+152 -129)
📝 komorebi/src/container.rs (+49 -67)
📝 komorebi/src/core/mod.rs (+16 -1)
📝 komorebi/src/focus_manager.rs (+5 -5)

...and 21 more files

📄 Description

The PR is based on #1494.

This PR brings a major internal cleanup to window matching and rule evaluation. It not only minimizes code, but also removes wasteful allocations and short-circuits at the first failure during composite rule checks.

Main improvements

  • Lazy evaluation of window properties:
    Previously, all Window properties (title, exe, class, path) were computed up front even if only one was actually needed by the rules. Now, each property is computed on demand—when the rule requires it—and never more than once per matching operation.
    For example, code like:

    if let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = (
        window.title(), window.exe(), window.class(), window.path()
    ) {
        should_float = should_act(&title, &exe_name, &class, &path, &floating_applications, &regex_identifiers).is_some();
    }
    

    is now:

    let should_float = window.matches_rules(
        &*FLOATING_APPLICATIONS.lock(),
        &REGEX_IDENTIFIERS.lock()
    );
    
  • Elimination of unnecessary allocations for composite rules:
    Previously, evaluating MatchingRule::Composite collected all results in a Vec before checking if they were all true. Now, evaluation is fully short-circuiting and allocation-free:

    MatchingRule::Composite(identifiers) => identifiers
      .iter()
      .all(|identifier| matches_identifier(matching, identifier, regex_identifiers)),
    
  • Smaller codebase. All boilerplate removed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/LGUG2Z/komorebi/pull/1495 **Author:** [@JustForFun88](https://github.com/JustForFun88) **Created:** 6/29/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `simple_should_act` --- ### 📝 Commits (6) - [`f9ea220`](https://github.com/LGUG2Z/komorebi/commit/f9ea220ccbeddc515279bcf5e6b8ee25a20ab9f2) Stop exposing Ring internals - [`862a55f`](https://github.com/LGUG2Z/komorebi/commit/862a55f06feca69a1d519b935427837e5f948905) Use `Arc<str>` and `WsElementId` instead of `String` - [`3020684`](https://github.com/LGUG2Z/komorebi/commit/3020684a16a143c18222e5cb39d460a6ab0c5af8) make serialize and deserialize compact - [`8cbf024`](https://github.com/LGUG2Z/komorebi/commit/8cbf0245cabcb1e920a175926959548f2b86c93d) Make `Window` internals private. - [`86b297f`](https://github.com/LGUG2Z/komorebi/commit/86b297f54b39fe80234568fc75d582d421890e0c) Make clippy happy - [`796e928`](https://github.com/LGUG2Z/komorebi/commit/796e928a04996127e40495e8739a3c34978ba5b3) Remove `should_act`, use `Window::matches_rule` ### 📊 Changes **41 files changed** (+1818 additions, -2177 deletions) <details> <summary>View changed files</summary> 📝 `komorebi-bar/src/bar.rs` (+18 -22) 📝 `komorebi-bar/src/main.rs` (+13 -23) 📝 `komorebi-bar/src/widgets/battery.rs` (+1 -1) 📝 `komorebi-bar/src/widgets/cpu.rs` (+3 -3) 📝 `komorebi-bar/src/widgets/date.rs` (+1 -1) 📝 `komorebi-bar/src/widgets/komorebi.rs` (+10 -11) 📝 `komorebi-bar/src/widgets/komorebi_layout.rs` (+2 -3) 📝 `komorebi-bar/src/widgets/memory.rs` (+3 -3) 📝 `komorebi-bar/src/widgets/mod.rs` (+5 -4) 📝 `komorebi-bar/src/widgets/network.rs` (+2 -2) 📝 `komorebi-bar/src/widgets/storage.rs` (+2 -2) 📝 `komorebi-bar/src/widgets/time.rs` (+1 -1) 📝 `komorebi-bar/src/widgets/update.rs` (+1 -1) 📝 `komorebi-gui/src/main.rs` (+8 -8) 📝 `komorebi/src/animation/prefix.rs` (+1 -1) 📝 `komorebi/src/border_manager/border.rs` (+54 -37) 📝 `komorebi/src/border_manager/mod.rs` (+152 -129) 📝 `komorebi/src/container.rs` (+49 -67) 📝 `komorebi/src/core/mod.rs` (+16 -1) 📝 `komorebi/src/focus_manager.rs` (+5 -5) _...and 21 more files_ </details> ### 📄 Description The PR is based on #1494. This PR brings a major internal cleanup to window matching and rule evaluation. It not only minimizes code, but also removes wasteful allocations and short-circuits at the first failure during composite rule checks. ## Main improvements - **Lazy evaluation of window properties:** Previously, all `Window` properties (`title`, `exe`, `class`, `path`) were computed up front even if only one was actually needed by the rules. Now, each property is computed on demand—*when* the rule requires it—and never more than once per matching operation. For example, code like: ```rust if let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = ( window.title(), window.exe(), window.class(), window.path() ) { should_float = should_act(&title, &exe_name, &class, &path, &floating_applications, &regex_identifiers).is_some(); } ``` is now: ```rust let should_float = window.matches_rules( &*FLOATING_APPLICATIONS.lock(), &REGEX_IDENTIFIERS.lock() ); ``` - **Elimination of unnecessary allocations for composite rules:** Previously, evaluating `MatchingRule::Composite` collected all results in a `Vec` before checking if they were all **true**. Now, evaluation is fully short-circuiting and allocation-free: ```rust MatchingRule::Composite(identifiers) => identifiers .iter() .all(|identifier| matches_identifier(matching, identifier, regex_identifiers)), ``` - **Smaller codebase.** All boilerplate removed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-01-05 14:55:15 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#1431