Skip to content
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

Optimize listen function #65

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

Aerion
Copy link
Contributor

@Aerion Aerion commented Jun 28, 2022

  • Use grep first to receive only the wanted lines
  • Flush the pending events to call output only once

With multiple occurrences of pulseaudio-control started, I noticed
that on quick changes (i.e. volume or iterating through the sinks),
the cpu usage increased a lot for the action.

pactl is quite noisy, and a single event can generate multiple
matching lines.

This commit reduces the calls to output to one per 100ms.

Copy link
Owner

@marioortizmanero marioortizmanero left a comment

Choose a reason for hiding this comment

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

Love it! Lots of infrequently-used flags. Great idea, thanks a bunch for the PR.

pulseaudio-control.bash Outdated Show resolved Hide resolved
- Use grep first to receive only the wanted lines
- Flush the pending events to call output only once

With multiple occurrences of pulseaudio-control started, I noticed
that on quick changes (i.e. volume or iterating through the sinks),
the cpu usage increased a lot for the action.

pactl is quite noisy, and a single event can generate multiple
matching lines.

This commit reduces the calls to output to one per 100ms.
@marioortizmanero
Copy link
Owner

Awesome. I've roughly measured the performant effect and you can actually see it. When generating lots of events (mainly increasing or decreasing the volume rapidly), htop reports 8-9% CPU load with the previous implementation. Now it's always under 2%.

Props for the idea! Merging once CI runs, thanks again.

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.

None yet

2 participants