SwiftBar: High CPU usage on streaming plugin

I’m facing issues with %CPU when running my streaming plugin. After some tests I came to the conclusion that the CPU usage can increase a lot if I print more than a single-line output in SwiftBar.

This is my original print function in the Python script:

print(
    '~~~',
    f'{coin}: {roi_fmt} ({roe_fmt}%) | color={color}',
    '---',
    f'Side: {side}',
    f'Entry Price: {entry_price}',
    f'Last Price: {last_price}',
    f'Quantity: {qty}',
    '---',
    f'Take Profit: {take_profit}',
    f'Stop Loss: {stop_loss}',
    sep='\n',
    flush=True
)

With the above multi-line output I had a lot of issues with high CPU usage which can get 100% sometimes apart of the app hanging, so I changed to this one-line output in order to avoid issues:

print(
    '~~~',
    f'{coin}: {roi_fmt} ({roe_fmt}%) | color={color}',
    sep='\n',
    flush=True
)

Another issue I have been facing is that the output in SwiftBar constantly disappear for a second or two during the stream as you can see in the following gif:

main_large

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 42 (42 by maintainers)

Commits related to this issue

Most upvoted comments

You can close this issue if you want, @melonamin. Thanks for your work on streaming plugins!

Plugin output looks good, overall looks like an OS rendering bug more than anything else. I’ll not invest time into further investigation at this moment