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

Test: Add benchmarking for widgets #137

Open
orhun opened this issue Apr 15, 2023 · 8 comments
Open

Test: Add benchmarking for widgets #137

orhun opened this issue Apr 15, 2023 · 8 comments
Labels
Effort: Good First Issue Good for newcomers without much Rust or Ratatui experiance. Apply only if willing to help implement Type: Enhancement New feature or request

Comments

@orhun
Copy link
Member

orhun commented Apr 15, 2023

Problem

There might be performance issues/concerns about tui widgets and adding benchmarks is important to uncover them.

Solution

Add benches for widgets. See #22 for an example.

Alternatives

None.

Additional context

#22

@orhun orhun added Type: Enhancement New feature or request Effort: Good First Issue Good for newcomers without much Rust or Ratatui experiance. Apply only if willing to help implement labels Apr 15, 2023
@Sufilevy
Copy link

I've looked at the linked issue, and tried to add a bench (for Block, just to try).

    #[bench]
    fn bench_title_rounded_corners(b: &mut test::Bencher) {
        b.iter(|| {
            Block::default()
                .borders(Borders::ALL)
                .title("Main block with round corners")
                .title_alignment(Alignment::Center)
                .border_type(BorderType::Rounded)
        })
    }

Does this look okay? I just took one of the example usages of Block in the repo, and I put it in a bench. Am I missing something? Is this the right direction for writing benches fi the widgets?

@sophacles
Copy link
Contributor

It's a good start. Most of the work for widgets is done in rendering, so I think it would be a good idea to set up a buffer outside of the measured func, and render to that buffer in the measured code.

@Sufilevy
Copy link

Sufilevy commented May 2, 2023

When benching the rendering of widgets, should I use the TestBackend?
Or should I create different rendering benches for crossterm and termion?

@sophacles
Copy link
Contributor

I don't know if you even need a backend tbh - doing something like

let area = Rect{...}; // put in size info
let buf = Buffer::empty(area);
b.iter(|| {
   let w = Block... // set up test
   w.render(area, buf);
});

Should capture the time it takes to render, and doesn't induce any backend related overhead.

(you may need to twiddle some of above, buf may need to be cloned for example, but that's the approach I'd start with).

@Sufilevy
Copy link

Sufilevy commented May 2, 2023

Got it. Thanks!

@Valentin271
Copy link
Member

Are you working on this @Sufilevy (or anyone else) ? Otherwise I'm interested in submitting a PR.

@Sufilevy
Copy link

Sufilevy commented Aug 4, 2023

You're welcome to!

Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 4, 2023
Added benchmarks to the block widget to uncover eventual performance issues

ratatui#137
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 5, 2023
Added benchmarks to the block widget to uncover eventual performance issues

ratatui#137
Valentin271 added a commit to Valentin271/ratatui that referenced this issue Aug 5, 2023
Added benchmarks to the block widget to uncover eventual performance issues

ratatui#137
@joshka joshka changed the title Add benchmarking for widgets Test: Add benchmarking for widgets Sep 28, 2023
@EdJoPaTo
Copy link
Contributor

EdJoPaTo commented Mar 4, 2024

Most of the work for widgets is done in rendering, so I think it would be a good idea to set up a buffer outside of the measured func, and render to that buffer in the measured code.

Most widgets are created on every render, so I think they should also be included in the benchmarks. Either they are fast and no problem or an issue shows up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort: Good First Issue Good for newcomers without much Rust or Ratatui experiance. Apply only if willing to help implement Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants