Skip to content

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

Open
JustForFun88 wants to merge 6 commits intoLGUG2Z:masterfrom
JustForFun88:simple_should_act
Open

refactor (window): Lazy, Single-pass Evaluation of Window Properties and Efficient Rule Matching#1495
JustForFun88 wants to merge 6 commits intoLGUG2Z:masterfrom
JustForFun88:simple_should_act

Conversation

@JustForFun88
Copy link
Contributor

@JustForFun88 JustForFun88 commented Jun 29, 2025

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.

@JustForFun88 JustForFun88 marked this pull request as draft June 29, 2025 17:53
@JustForFun88 JustForFun88 force-pushed the simple_should_act branch 2 times, most recently from 1febb74 to 89ddc9b Compare June 30, 2025 02:52
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.

1 participant