Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Insert a small sleep when polling stdin
Resolves #48
Here is how to reproduce this issue
This is what happens in
![Screenshot 2025-01-23 at 11 34 21 AM](https://private-user-images.githubusercontent.com/4130608/406153772-4a47698e-48da-4bf7-bb76-85bcbdf9c657.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMjQzNDMsIm5iZiI6MTczOTAyNDA0MywicGF0aCI6Ii80MTMwNjA4LzQwNjE1Mzc3Mi00YTQ3Njk4ZS00OGRhLTRiZjctYmI3Ni04NWJjYmRmOWM2NTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTQxNDAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDMzYzg5NjQ0ZGU0NjhjMGM4NWZlOTRlYzNlZWRkOWFjNTg4NGYxNzczNDM5YjYxNTM5YWJlNGQ5MTUxYjA3NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.o9XgBIw9_GpnoWtdeRRfN8ZC0lOqyA508Wtrou6YCQ8)
main
now. 100% CPU usage when pipingI 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](https://private-user-images.githubusercontent.com/4130608/406153770-1a9dd9c4-1e16-494f-9760-ea0ddbb9a251.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMjQzNDMsIm5iZiI6MTczOTAyNDA0MywicGF0aCI6Ii80MTMwNjA4LzQwNjE1Mzc3MC0xYTlkZDljNC0xZTE2LTQ5NGYtOTc2MC1lYTBkZGJiOWEyNTEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTQxNDAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjE2NmM3MThlZWUzZjI1NjRlNTI3NTczNDZlOTRlYzcyOTMwNzgyYWIwMTI5YTdkZjUyYmIwNWQxNWFlZThiNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.TLsfp3xLck6iETCWB8km960UvpIXp-f3G6y4DCD3uYQ)
5 ms used about 0.7% cpu.
![Screenshot 2025-01-23 at 11 35 14 AM](https://private-user-images.githubusercontent.com/4130608/406153762-b0bbb1b5-4331-4ef3-9f71-974d65c5dddc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMjQzNDMsIm5iZiI6MTczOTAyNDA0MywicGF0aCI6Ii80MTMwNjA4LzQwNjE1Mzc2Mi1iMGJiYjFiNS00MzMxLTRlZjMtOWY3MS05NzRkNjVjNWRkZGMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTQxNDAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NmY1OWMyMDZjZmYzMDhlMjkzYTY2NDQ1NTExZWQzMWM1MWRhYmViZGFiZGE3ZGUzMWNmYjA3MWZhNGNiM2ZjZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KOh9ZKT8jCk2hUh84eeGKiaYutleN4dwXAWV06QXqCY)
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.