ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.96k stars 274 forks source link

Performance considerations with using `stderr` in the book #1220

Open vyfor opened 1 week ago

vyfor commented 1 week ago

Problem

I've been trying to make a TUI app using Ratatui for the past few days, but at some point, I started experiencing slow UI renders, as shown below:

https://github.com/ratatui-org/ratatui/assets/92883017/4dee6113-0e9f-4a20-b755-841317dbe471

Upon investigating further, I noticed that when I was following this guide, I replaced stdout with stderr. Since stderr seems to be unbuffered in most cases, it can cause performance issues.

Solution

I'd either inform the user that using stderr on some terminals may cause performance issues, or switch to using stdout altogether. It took me quite some time to trace back the issue, so this is something worth reconsidering.

joshka commented 1 week ago

Thanks for pointing this out.

https://ratatui.rs/faq/#should-i-use-stdout-or-stderr has some of this, but there should be something in the concepts section

That specific guide is much too opinionated for my liking, without showing why you'd choose certain things, and why not. It's the wrong amount of code that will tend to cause the sorts of problems you faced...

vyfor commented 1 week ago

Oh hmm, I overlooked the FAQ and blindly assumed both streams were equivalent, which back fired. Regardless, a notice or link to the relevant FAQ section could help clarify this for newcomers.