Skip to content

Event-based provider API #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ALinuxPerson
Copy link
Contributor

This pull request implements a new event-based provider API for any conforming space providers. The main motivation for this PR is to address the high CPU usage of Barik and its parent provider process (i.e. yabai, aerospace), which we'll refer to as PPP from now on.

Currently, Barik uses a polling/timer-based way to check for changes in the spaces or windows by querying the spaces and their windows every 0.1 seconds. While simple, this is vastly inefficient for both Barik and the PPP because of the vast amount of system resources and calculations used every time the space querying function is called.

This PR implements a new approach into monitoring for space changes--why not rely on events from the PPP instead? This way, the cost for parsing and interpreting the space changes from the PPP is minimal and, most importantly, only happens when it needs to.

@mocki-toki
Copy link
Owner

In my experiments, I used the following approach: I create a Unix socket in a temporary folder, listen to it, and create a yabai signal that sends requests there.

I think the following signals would be useful: window_created, window_destroyed, window_focused, window_title_changed, space_created, space_destroyed, space_changed.

Here is an example of sending data to the socket:

/opt/homebrew/bin/yabai -m signal --remove yabai_event_listener_trigger 2>/dev/null;

/opt/homebrew/bin/yabai -m signal --add event=space_changed \
    label=yabai_event_listener_trigger \
    action=' \
        bash -c " \
            spaces=$( /opt/homebrew/bin/yabai -m query --spaces ); \
            windows=$( /opt/homebrew/bin/yabai -m query --windows ); \
            echo {\\\"spaces\\\":$spaces,\\\"windows\\\":$windows} \
        " \
    '  \
| nc -U /tmp/yabai_events.sock

@mocki-toki mocki-toki linked an issue Mar 17, 2025 that may be closed by this pull request
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.

Improving perfomance when working WM
2 participants