toolong
toolong copied to clipboard
Fix Very high CPU usage when piping
Insert a small sleep when polling stdin
Resolves https://github.com/Textualize/toolong/issues/48
Here is how to reproduce this issue
$ tl --version
tl, version 1.4.0
$ echo '{"foo": "bar"}' > /tmp/log.json
$ cat /tmp/log.json | tl
This is what happens in main now. 100% CPU usage when piping
I added a small sleep when there is nothing to read. I tested 1 ms and 5 ms.
1 ms used about 2% cpu.
5 ms used about 0.7% cpu.
I would guess 5 ms will not be very noticable, but if it is we can go down to 1.
Testing
I tried piping in a 40MB file and did not notice any difference in performance with or without the sleep.
@willmcgugan Can you please take a look
Works for me :)