Skip to content

Conversation

@mckaymatt
Copy link

Insert a small sleep when polling stdin

Resolves #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
Screenshot 2025-01-23 at 11 34 21 AM

I added a small sleep when there is nothing to read. I tested 1 ms and 5 ms.

1 ms used about 2% cpu.
Screenshot 2025-01-23 at 11 34 47 AM

5 ms used about 0.7% cpu.
Screenshot 2025-01-23 at 11 35 14 AM

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.

Insert a small sleep when polling stdin Textualize#48
@mckaymatt mckaymatt marked this pull request as ready for review January 23, 2025 17:53
@mattviasat
Copy link

@willmcgugan Can you please take a look

@nickma82
Copy link

nickma82 commented Nov 6, 2025

Works for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants