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

high cpu usage #38

Closed
m040601 opened this issue Sep 7, 2021 · 7 comments · Fixed by #39 or #41
Closed

high cpu usage #38

m040601 opened this issue Sep 7, 2021 · 7 comments · Fixed by #39 or #41

Comments

@m040601
Copy link

m040601 commented Sep 7, 2021

First of all thank you for your work in this clever tool.

I've been following it and testing it, since the first releases.
I've been comparing it and testing it with others that provide similar "hinting" to copy to the tmux buffer.

Everything works fine.

Except, when there's nothing to find or no regex to match (CASE1).

That is, for ex. , if i open a new tmux window, with a fresh empty buffer, with nothing being displayed except my prompt.

When i fire tmux-fastcopy, it simply greys out everything, and the CPU usage shoots up.

I have to abort it with C-c. Nothing gets copied to the buffer.

If I have a little more to be found (CASE2) then it works as usual.
https://imgur.com/a/zNUKall

I have to say that I use the released compiled version, on ArchLinux.
I simply have this on my .tmux.conf,

bind-key F run-shell -b ~/.tmux.d/experiments/tmux-fastcopy

@abhinav
Copy link
Owner

abhinav commented Sep 8, 2021

Thanks for the report @m040601! I was able to reproduce the issue locally.
I'll try to have a fix shortly.

abhinav added a commit that referenced this issue Sep 8, 2021
If there's a single entry in the collection of matches, our huffman
implementation will return an empty label. That results in an infinite
loop when rendering because we attempt to match empy input to an empty
label.

Resolve this by handling the single match case separately.

Fixes #38
abhinav added a commit that referenced this issue Sep 8, 2021
If there's a single entry in the collection of matches, our huffman
implementation will return an empty label. That results in an infinite
loop when rendering because we attempt to match empy input to an empty
label.

Resolve this by handling the single match case separately.

Fixes #38
abhinav added a commit that referenced this issue Sep 8, 2021
This releases v0.5.0 with a fix for #38.
abhinav added a commit that referenced this issue Sep 8, 2021
This releases v0.5.0 with a fix for #38.
@abhinav
Copy link
Owner

abhinav commented Sep 8, 2021

Fix released in v0.5.0. Thanks again @m040601.

@m040601
Copy link
Author

m040601 commented Sep 8, 2021

Nice. I'm not even a programmer, so I wasnt even sure this was some coding problem.
I've also tested 0.5 and it does find even single matches now, suggests the hint key, and copies to the buffer.

The only thing I think could be improved later is the high CPU usage.
That is, if I just stay there, without doing nothing, the CPU stays at 100% until i decide either to cancel with Control-C, or accept the hint 'a'. Maybe the go binary compilation could be optimized with some flag ??? No problem with exagerate memory consumption seen. It's really just the high cpu usage.

PS: By the way. Good thing that you provide binaries for different plattforms.
This might be very usefull in my little underpowerd Raspberry Pi's. (and other arm's)

@abhinav
Copy link
Owner

abhinav commented Sep 8, 2021

Thanks for the short and actionable bug report! It made it easy to track the issue down.

Ah, I thought the high cpu was related to the empty match, but I didn't confirm that. I'll dig into that separately. I suspect it's the render loop.

@abhinav abhinav reopened this Sep 8, 2021
@abhinav
Copy link
Owner

abhinav commented Sep 9, 2021

Never mind, it wasn't the render loop. I found the root cause; it had to do with logging. Fix incoming.

abhinav added a commit that referenced this issue Sep 9, 2021
The way log tailing was implemented, we were effectively spin looping
when the source had no bytes to produce but also had not yet hit EOF.

    while !eof {
        read(f)
    }

Fix this by spinning only if it had bytes to produce (indicating that
there may be more), and once it begins producing zero bytes, use the
same delay we would use for EOF.

    do {
        n = read(f)
    } while (n > 0 && !eof)

    if eof || n == 0 { sleep; retry }

This resolves 100% CPU usage when idling.

Fixes #38
abhinav added a commit that referenced this issue Sep 9, 2021
The way log tailing was implemented, we were effectively spin looping
when the source had no bytes to produce but also had not yet hit EOF.

    while !eof {
        read(f)
    }

Fix this by spinning only if it had bytes to produce (indicating that
there may be more), and once it begins producing zero bytes, use the
same delay we would use for EOF.

    do {
        n = read(f)
    } while (n > 0 && !eof)

    if eof || n == 0 { sleep; retry }

This resolves 100% CPU usage when idling.

Fixes #38
@abhinav
Copy link
Owner

abhinav commented Sep 9, 2021

This should be fixed in v0.5.1.

Before:
image

After:
image

Thanks again @m040601.

@m040601
Copy link
Author

m040601 commented Sep 11, 2021

This should be fixed in v0.5.1.

Yeap. Tested and confirmed on my system too. Can't hear my fans spinning crazy, can't see anything abnormal in htop anymore. Great job !

abhinav added a commit to abhinav/huffman-go that referenced this issue Nov 28, 2024
If there's a single entry in the collection of matches, our huffman
implementation will return an empty label. That results in an infinite
loop when rendering because we attempt to match empy input to an empty
label.

Resolve this by handling the single match case separately.

Fixes abhinav/tmux-fastcopy#38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants