Skip to content

Conversation

ogoffart
Copy link
Member

That way when a layout is dirty because some text inside changed, we don't redraw the whole screen if most item don't move.

(PR best viewed commit by commit)

@ogoffart
Copy link
Member Author

cargo bench -p printerdemo_mcu

Before:


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

bench                fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ full                            │               │               │               │         │
│  ├─ Rgb565Pixel    541.7 µs      │ 1.023 ms      │ 754.2 µs      │ 763.8 µs      │ 100     │ 100
│  │                 max alloc:    │               │               │               │         │
│  │                   390         │ 390           │ 390           │ 408.4         │         │
│  │                   43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 44.84 KB      │         │
│  │                 alloc:        │               │               │               │         │
│  │                   3057        │ 3057          │ 3057          │ 3057          │         │
│  │                   179 KB      │ 179 KB        │ 179 KB        │ 179 KB        │         │
│  │                 dealloc:      │               │               │               │         │
│  │                   3056        │ 3056          │ 3056          │ 3033          │         │
│  │                   203.6 KB    │ 203.6 KB      │ 203.6 KB      │ 202.3 KB      │         │
│  │                 grow:         │               │               │               │         │
│  │                   251         │ 250           │ 250           │ 250.2         │         │
│  │                   24.74 KB    │ 24.61 KB      │ 24.61 KB      │ 24.83 KB      │         │
│  ╰─ Rgb<u8>        1.093 ms      │ 1.577 ms      │ 1.334 ms      │ 1.33 ms       │ 100     │ 100
│                    max alloc:    │               │               │               │         │
│                      390         │ 390           │ 390           │ 390           │         │
│                      43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 43.91 KB      │         │
│                    alloc:        │               │               │               │         │
│                      3057        │ 3057          │ 3057          │ 3057          │         │
│                      179 KB      │ 179 KB        │ 179 KB        │ 179 KB        │         │
│                    dealloc:      │               │               │               │         │
│                      3056        │ 3056          │ 3056          │ 3056          │         │
│                      203.6 KB    │ 203.6 KB      │ 203.6 KB      │ 203.6 KB      │         │
│                    grow:         │               │               │               │         │
│                      250         │ 250           │ 250           │ 250           │         │
│                      24.61 KB    │ 24.61 KB      │ 24.61 KB      │ 24.73 KB      │         │
╰─ render_only                     │               │               │               │         │
   ├─ Rgb565Pixel                  │               │               │               │         │
   │  ├─ FullBuffer  266.3 µs      │ 292.6 µs      │ 268.7 µs      │ 269.4 µs      │ 100     │ 100
   │  │              max alloc:    │               │               │               │         │
   │  │                2           │ 186           │ 2             │ 3.84          │         │
   │  │                464 B       │ 6.352 KB      │ 464 B         │ 522.8 B       │         │
   │  │              alloc:        │               │               │               │         │
   │  │                665         │ 665           │ 665           │ 665           │         │
   │  │                23.9 KB     │ 23.9 KB       │ 23.9 KB       │ 23.9 KB       │         │
   │  │              dealloc:      │               │               │               │         │
   │  │                665         │ 481           │ 665           │ 663.1         │         │
   │  │                27.37 KB    │ 21.48 KB      │ 27.37 KB      │ 27.31 KB      │         │
   │  │              grow:         │               │               │               │         │
   │  │                30          │ 30            │ 30            │ 30            │         │
   │  │                3.472 KB    │ 3.472 KB      │ 3.472 KB      │ 3.472 KB      │         │
   │  ╰─ LineByLine  278.6 µs      │ 298.6 µs      │ 282.4 µs      │ 283.1 µs      │ 100     │ 100
   │                 max alloc:    │               │               │               │         │
   │                   5           │ 189           │ 5             │ 6.84          │         │
   │                   7.84 KB     │ 13.72 KB      │ 7.84 KB       │ 7.898 KB      │         │
   │                 alloc:        │               │               │               │         │
   │                   668         │ 668           │ 668           │ 668           │         │
   │                   24.23 KB    │ 24.23 KB      │ 24.23 KB      │ 24.23 KB      │         │
   │                 dealloc:      │               │               │               │         │
   │                   668         │ 484           │ 668           │ 666.1         │         │
   │                   34.75 KB    │ 28.86 KB      │ 34.75 KB      │ 34.69 KB      │         │
   │                 grow:         │               │               │               │         │
   │                   41          │ 41            │ 41            │ 41            │         │
   │                   10.52 KB    │ 10.52 KB      │ 10.52 KB      │ 10.52 KB      │         │
   ╰─ Rgb<u8>                      │               │               │               │         │
      ├─ FullBuffer  357.4 µs      │ 393.9 µs      │ 361 µs        │ 361.8 µs      │ 100     │ 100
      │              max alloc:    │               │               │               │         │
      │                2           │ 2             │ 2             │ 3.84          │         │
      │                464 B       │ 464 B         │ 464 B         │ 522.8 B       │         │
      │              alloc:        │               │               │               │         │
      │                665         │ 665           │ 665           │ 665           │         │
      │                23.9 KB     │ 23.9 KB       │ 23.9 KB       │ 23.9 KB       │         │
      │              dealloc:      │               │               │               │         │
      │                665         │ 665           │ 665           │ 663.1         │         │
      │                27.37 KB    │ 27.37 KB      │ 27.37 KB      │ 27.31 KB      │         │
      │              grow:         │               │               │               │         │
      │                30          │ 30            │ 30            │ 30            │         │
      │                3.472 KB    │ 3.472 KB      │ 3.472 KB      │ 3.472 KB      │         │
      ╰─ LineByLine  370.9 µs      │ 387.3 µs      │ 374.8 µs      │ 375.2 µs      │ 100     │ 100
                     max alloc:    │               │               │               │         │
                       5           │ 189           │ 5             │ 6.84          │         │
                       7.84 KB     │ 13.72 KB      │ 7.84 KB       │ 7.898 KB      │         │
                     alloc:        │               │               │               │         │
                       668         │ 668           │ 668           │ 668           │         │
                       24.23 KB    │ 24.23 KB      │ 24.23 KB      │ 24.23 KB      │         │
                     dealloc:      │               │               │               │         │
                       668         │ 484           │ 668           │ 666.1         │         │
                       34.75 KB    │ 28.86 KB      │ 34.75 KB      │ 34.69 KB      │         │
                     grow:         │               │               │               │         │
                       41          │ 41            │ 41            │ 41            │         │
                       10.52 KB    │ 10.52 KB      │ 10.52 KB      │ 10.52 KB      │         │


After:

bench                fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ full                            │               │               │               │         │
│  ├─ Rgb565Pixel    545.4 µs      │ 963.8 µs      │ 746.5 µs      │ 747.6 µs      │ 100     │ 100
│  │                 max alloc:    │               │               │               │         │
│  │                   390         │ 390           │ 390           │ 410.7         │         │
│  │                   43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 44.97 KB      │         │
│  │                 alloc:        │               │               │               │         │
│  │                   3183        │ 3183          │ 3183          │ 3183          │         │
│  │                   187.8 KB    │ 187.8 KB      │ 187.8 KB      │ 187.9 KB      │         │
│  │                 dealloc:      │               │               │               │         │
│  │                   3182        │ 3182          │ 3182          │ 3157          │         │
│  │                   210.9 KB    │ 210.9 KB      │ 210.9 KB      │ 209.5 KB      │         │
│  │                 grow:         │               │               │               │         │
│  │                   237         │ 236           │ 237           │ 236.2         │         │
│  │                   23.17 KB    │ 23.04 KB      │ 23.3 KB       │ 23.26 KB      │         │
│  ╰─ Rgb<u8>        1.071 ms      │ 1.56 ms       │ 1.303 ms      │ 1.303 ms      │ 100     │ 100
│                    max alloc:    │               │               │               │         │
│                      390         │ 390           │ 390           │ 390           │         │
│                      43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 43.91 KB      │         │
│                    alloc:        │               │               │               │         │
│                      3183        │ 3183          │ 3183          │ 3183          │         │
│                      187.8 KB    │ 187.8 KB      │ 187.8 KB      │ 187.8 KB      │         │
│                    dealloc:      │               │               │               │         │
│                      3182        │ 3182          │ 3182          │ 3182          │         │
│                      210.9 KB    │ 210.9 KB      │ 210.9 KB      │ 210.9 KB      │         │
│                    grow:         │               │               │               │         │
│                      236         │ 236           │ 236           │ 236           │         │
│                      23.04 KB    │ 23.04 KB      │ 23.04 KB      │ 23.17 KB      │         │
╰─ render_only                     │               │               │               │         │
   ├─ Rgb565Pixel                  │               │               │               │         │
   │  ├─ FullBuffer  219.1 µs      │ 236.7 µs      │ 223.4 µs      │ 223.9 µs      │ 100     │ 100
   │  │              max alloc:    │               │               │               │         │
   │  │                2           │ 186           │ 2             │ 3.84          │         │
   │  │                464 B       │ 6.352 KB      │ 464 B         │ 522.8 B       │         │
   │  │              alloc:        │               │               │               │         │
   │  │                791         │ 791           │ 791           │ 791           │         │
   │  │                26.65 KB    │ 26.65 KB      │ 26.65 KB      │ 26.65 KB      │         │
   │  │              dealloc:      │               │               │               │         │
   │  │                791         │ 607           │ 791           │ 789.1         │         │
   │  │                28.56 KB    │ 22.67 KB      │ 28.56 KB      │ 28.5 KB       │         │
   │  │              grow:         │               │               │               │         │
   │  │                16          │ 16            │ 16            │ 16            │         │
   │  │                1.904 KB    │ 1.904 KB      │ 1.904 KB      │ 1.904 KB      │         │
   │  ╰─ LineByLine  227.7 µs      │ 249 µs        │ 233.2 µs      │ 233.8 µs      │ 100     │ 100
   │                 max alloc:    │               │               │               │         │
   │                   5           │ 5             │ 5             │ 6.84          │         │
   │                   7.84 KB     │ 7.84 KB       │ 7.84 KB       │ 7.898 KB      │         │
   │                 alloc:        │               │               │               │         │
   │                   794         │ 794           │ 794           │ 794           │         │
   │                   26.98 KB    │ 26.98 KB      │ 26.98 KB      │ 26.98 KB      │         │
   │                 dealloc:      │               │               │               │         │
   │                   794         │ 794           │ 794           │ 792.1         │         │
   │                   35.93 KB    │ 35.93 KB      │ 35.93 KB      │ 35.87 KB      │         │
   │                 grow:         │               │               │               │         │
   │                   27          │ 27            │ 27            │ 27            │         │
   │                   8.952 KB    │ 8.952 KB      │ 8.952 KB      │ 8.952 KB      │         │
   ╰─ Rgb<u8>                      │               │               │               │         │
      ├─ FullBuffer  305 µs        │ 338.4 µs      │ 311.3 µs      │ 316.6 µs      │ 100     │ 100
      │              max alloc:    │               │               │               │         │
      │                2           │ 2             │ 2             │ 3.84          │         │
      │                464 B       │ 464 B         │ 464 B         │ 522.8 B       │         │
      │              alloc:        │               │               │               │         │
      │                791         │ 791           │ 791           │ 791           │         │
      │                26.65 KB    │ 26.65 KB      │ 26.65 KB      │ 26.65 KB      │         │
      │              dealloc:      │               │               │               │         │
      │                791         │ 791           │ 791           │ 789.1         │         │
      │                28.56 KB    │ 28.56 KB      │ 28.56 KB      │ 28.5 KB       │         │
      │              grow:         │               │               │               │         │
      │                16          │ 16            │ 16            │ 16            │         │
      │                1.904 KB    │ 1.904 KB      │ 1.904 KB      │ 1.904 KB      │         │
      ╰─ LineByLine  320.1 µs      │ 340.2 µs      │ 325.5 µs      │ 325.9 µs      │ 100     │ 100
                     max alloc:    │               │               │               │         │
                       5           │ 189           │ 5             │ 6.84          │         │
                       7.84 KB     │ 13.72 KB      │ 7.84 KB       │ 7.898 KB      │         │
                     alloc:        │               │               │               │         │
                       794         │ 794           │ 794           │ 794           │         │
                       26.98 KB    │ 26.98 KB      │ 26.98 KB      │ 26.98 KB      │         │
                     dealloc:      │               │               │               │         │
                       794         │ 610           │ 794           │ 792.1         │         │
                       35.93 KB    │ 30.04 KB      │ 35.93 KB      │ 35.87 KB      │         │
                     grow:         │               │               │               │         │
                       27          │ 27            │ 27            │ 27            │         │
                       8.952 KB    │ 8.952 KB      │ 8.952 KB      │ 8.952 KB      │         │

Copy link
Member

@tronical tronical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful - thank you!

@ogoffart
Copy link
Member Author

This is dangerous, I hope i didn't break anything.
And I hope the memory usage increase is tolerable. I wonder if there are other ways. a PropertyTracker is in fact quite epxensive. I'm thinking maybe we don't need a tracker for the geometry and always query them?

@tronical
Copy link
Member

This is dangerous, I hope i didn't break anything. And I hope the memory usage increase is tolerable. I wonder if there are other ways. a PropertyTracker is in fact quite epxensive. I'm thinking maybe we don't need a tracker for the geometry and always query them?

I was thinking the same. It should be relatively fast anyway.

@ogoffart ogoffart force-pushed the olivier/swrenderer branch 2 times, most recently from 88a5796 to c880ecf Compare September 22, 2025 08:25
@ogoffart
Copy link
Member Author

New patch that do no longer have two tracker, but just one for the rendering:

bench                fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ full                            │               │               │               │         │
│  ├─ Rgb565Pixel    464.1 µs      │ 883.7 µs      │ 647.1 µs      │ 660.9 µs      │ 100     │ 100
│  │                 max alloc:    │               │               │               │         │
│  │                   390         │ 390           │ 390           │ 405.1         │         │
│  │                   43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 44.74 KB      │         │
│  │                 alloc:        │               │               │               │         │
│  │                   2495        │ 2495          │ 2495          │ 2495          │         │
│  │                   154.4 KB    │ 154.4 KB      │ 154.4 KB      │ 154.4 KB      │         │
│  │                 dealloc:      │               │               │               │         │
│  │                   2494        │ 2494          │ 2494          │ 2475          │         │
│  │                   172.8 KB    │ 172.8 KB      │ 172.8 KB      │ 171.7 KB      │         │
│  │                 grow:         │               │               │               │         │
│  │                   190         │ 188           │ 188           │ 188.2         │         │
│  │                   18.72 KB    │ 18.47 KB      │ 18.47 KB      │ 18.69 KB      │         │
│  ╰─ Rgb<u8>        970.9 µs      │ 1.492 ms      │ 1.199 ms      │ 1.2 ms        │ 100     │ 100
│                    max alloc:    │               │               │               │         │
│                      390         │ 390           │ 390           │ 390           │         │
│                      43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 43.98 KB      │         │
│                    alloc:        │               │               │               │         │
│                      2495        │ 2495          │ 2495          │ 2495          │         │
│                      154.4 KB    │ 154.4 KB      │ 154.4 KB      │ 154.4 KB      │         │
│                    dealloc:      │               │               │               │         │
│                      2494        │ 2494          │ 2494          │ 2494          │         │
│                      172.8 KB    │ 172.8 KB      │ 172.8 KB      │ 172.8 KB      │         │
│                    grow:         │               │               │               │         │
│                      188         │ 188           │ 188           │ 188           │         │
│                      18.47 KB    │ 18.47 KB      │ 18.47 KB      │ 18.59 KB      │         │
╰─ render_only                     │               │               │               │         │
   ├─ Rgb565Pixel                  │               │               │               │         │
   │  ├─ FullBuffer  442.4 µs      │ 515.5 µs      │ 459.2 µs      │ 461.3 µs      │ 100     │ 100
   │  │              max alloc:    │               │               │               │         │
   │  │                2           │ 29            │ 2             │ 2.27          │         │
   │  │                464 B       │ 1.328 KB      │ 464 B         │ 472.6 B       │         │
   │  │              alloc:        │               │               │               │         │
   │  │                718         │ 718           │ 718           │ 718           │         │
   │  │                29.65 KB    │ 29.65 KB      │ 29.65 KB      │ 29.65 KB      │         │
   │  │              dealloc:      │               │               │               │         │
   │  │                718         │ 691           │ 718           │ 717.7         │         │
   │  │                36.13 KB    │ 35.27 KB      │ 36.13 KB      │ 36.12 KB      │         │
   │  │              grow:         │               │               │               │         │
   │  │                64          │ 64            │ 64            │ 64            │         │
   │  │                6.48 KB     │ 6.48 KB       │ 6.48 KB       │ 6.48 KB       │         │
   │  ╰─ LineByLine  465.2 µs      │ 504.5 µs      │ 472.8 µs      │ 475.2 µs      │ 100     │ 100
   │                 max alloc:    │               │               │               │         │
   │                   5           │ 32            │ 5             │ 5.27          │         │
   │                   7.84 KB     │ 8.704 KB      │ 7.84 KB       │ 7.848 KB      │         │
   │                 alloc:        │               │               │               │         │
   │                   721         │ 721           │ 721           │ 721           │         │
   │                   29.98 KB    │ 29.98 KB      │ 29.98 KB      │ 29.98 KB      │         │
   │                 dealloc:      │               │               │               │         │
   │                   721         │ 694           │ 721           │ 720.7         │         │
   │                   43.51 KB    │ 42.64 KB      │ 43.51 KB      │ 43.5 KB       │         │
   │                 grow:         │               │               │               │         │
   │                   75          │ 75            │ 75            │ 75            │         │
   │                   13.52 KB    │ 13.52 KB      │ 13.52 KB      │ 13.52 KB      │         │
   ╰─ Rgb<u8>                      │               │               │               │         │
      ├─ FullBuffer  538.6 µs      │ 596.2 µs      │ 551.4 µs      │ 552.6 µs      │ 100     │ 100
      │              max alloc:    │               │               │               │         │
      │                2           │ 29            │ 2             │ 2.27          │         │
      │                464 B       │ 1.328 KB      │ 464 B         │ 472.6 B       │         │
      │              alloc:        │               │               │               │         │
      │                718         │ 718           │ 718           │ 718           │         │
      │                29.65 KB    │ 29.65 KB      │ 29.65 KB      │ 29.65 KB      │         │
      │              dealloc:      │               │               │               │         │
      │                718         │ 691           │ 718           │ 717.7         │         │
      │                36.13 KB    │ 35.27 KB      │ 36.13 KB      │ 36.12 KB      │         │
      │              grow:         │               │               │               │         │
      │                64          │ 64            │ 64            │ 64            │         │
      │                6.48 KB     │ 6.48 KB       │ 6.48 KB       │ 6.48 KB       │         │
      ╰─ LineByLine  552.6 µs      │ 598.4 µs      │ 568.4 µs      │ 570.5 µs      │ 100     │ 100
                     max alloc:    │               │               │               │         │
                       5           │ 32            │ 5             │ 5.27          │         │
                       7.84 KB     │ 8.704 KB      │ 7.84 KB       │ 7.848 KB      │         │
                     alloc:        │               │               │               │         │
                       721         │ 721           │ 721           │ 721           │         │
                       29.98 KB    │ 29.98 KB      │ 29.98 KB      │ 29.98 KB      │         │
                     dealloc:      │               │               │               │         │
                       721         │ 694           │ 721           │ 720.7         │         │
                       43.51 KB    │ 42.64 KB      │ 43.51 KB      │ 43.5 KB       │         │
                     grow:         │               │               │               │         │
                       75          │ 75            │ 75            │ 75            │         │
                       13.52 KB    │ 13.52 KB      │ 13.52 KB      │ 13.52 KB      │         │

The result is that full is faster and takes less memory, however render_only is slower and takes more memory.
The reason is that computing the dirty region now needs to recompute the geometry of every item. The bottleneck is the call to i_slint_core::items::SimpleTextVTable::bounding_rect which recompute the layout.
(What I realized is that this benchmark uses RepaintBufferType::NewBuffer that shouldn't even need to compute the dirty region, but still does.)

As for the test failure, this is because

x: ZeroHelper.zero * 5px / ZeroHelper.zero;
has a coordinate that is NaN and before, it would rely on the tracker to figure out what changed. But now, it relies on the != operator between bounding rect. And NaN is never equal to itself.

@ogoffart ogoffart force-pushed the olivier/swrenderer branch 2 times, most recently from 8137d32 to 804f731 Compare October 8, 2025 14:36
@ogoffart
Copy link
Member Author

ogoffart commented Oct 8, 2025

The actual reason why this was slower and taking more memory was because we were still visiting clipped (invisible) items. After that being fixed, we are much faster.

Now with the latest change from this patch:

Timer precision: 28 ns
bench                fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ full                            │               │               │               │         │
│  ├─ Rgb565Pixel    425.1 µs      │ 1.456 ms      │ 500.1 µs      │ 535.1 µs      │ 100     │ 100
│  │                 max alloc:    │               │               │               │         │
│  │                   390         │ 1869          │ 390           │ 404.7         │         │
│  │                   43.91 KB    │ 124.4 KB      │ 43.91 KB      │ 44.74 KB      │         │
│  │                 alloc:        │               │               │               │         │
│  │                   2334        │ 2348          │ 2334          │ 2334          │         │
│  │                   143.9 KB    │ 146.8 KB      │ 143.9 KB      │ 143.9 KB      │         │
│  │                 dealloc:      │               │               │               │         │
│  │                   2333        │ 481           │ 2333          │ 2314          │         │
│  │                   157.8 KB    │ 46.75 KB      │ 157.8 KB      │ 156.7 KB      │         │
│  │                 grow:         │               │               │               │         │
│  │                   140         │ 146           │ 140           │ 140.2         │         │
│  │                   13.89 KB    │ 23.97 KB      │ 13.89 KB      │ 14.09 KB      │         │
│  ╰─ Rgb<u8>        651.8 µs      │ 859.1 µs      │ 735.8 µs      │ 740.9 µs      │ 100     │ 100
│                    max alloc:    │               │               │               │         │
│                      390         │ 390           │ 390           │ 390           │         │
│                      43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 43.99 KB      │         │
│                    alloc:        │               │               │               │         │
│                      2334        │ 2334          │ 2334          │ 2334          │         │
│                      143.9 KB    │ 143.9 KB      │ 143.9 KB      │ 143.9 KB      │         │
│                    dealloc:      │               │               │               │         │
│                      2333        │ 2333          │ 2333          │ 2333          │         │
│                      157.8 KB    │ 157.8 KB      │ 157.8 KB      │ 157.8 KB      │         │
│                    grow:         │               │               │               │         │
│                      140         │ 140           │ 140           │ 140           │         │
│                      13.89 KB    │ 13.89 KB      │ 13.89 KB      │ 13.99 KB      │         │
╰─ render_only                     │               │               │               │         │
   ├─ Rgb565Pixel                  │               │               │               │         │
   │  ├─ FullBuffer  197.8 µs      │ 218.2 µs      │ 200.2 µs      │ 200.7 µs      │ 100     │ 100
   │  │              max alloc:    │               │               │               │         │
   │  │                2           │ 29            │ 2             │ 2.27          │         │
   │  │                464 B       │ 1.328 KB      │ 464 B         │ 472.6 B       │         │
   │  │              alloc:        │               │               │               │         │
   │  │                565         │ 565           │ 565           │ 565           │         │
   │  │                19.42 KB    │ 19.42 KB      │ 19.42 KB      │ 19.42 KB      │         │
   │  │              dealloc:      │               │               │               │         │
   │  │                565         │ 538           │ 565           │ 564.7         │         │
   │  │                21.32 KB    │ 20.46 KB      │ 21.32 KB      │ 21.31 KB      │         │
   │  │              grow:         │               │               │               │         │
   │  │                16          │ 16            │ 16            │ 16            │         │
   │  │                1.904 KB    │ 1.904 KB      │ 1.904 KB      │ 1.904 KB      │         │
   │  ╰─ LineByLine  211.2 µs      │ 238.8 µs      │ 214.5 µs      │ 215 µs        │ 100     │ 100
   │                 max alloc:    │               │               │               │         │
   │                   5           │ 32            │ 5             │ 5.27          │         │
   │                   7.84 KB     │ 8.704 KB      │ 7.84 KB       │ 7.848 KB      │         │
   │                 alloc:        │               │               │               │         │
   │                   568         │ 568           │ 568           │ 568           │         │
   │                   19.75 KB    │ 19.75 KB      │ 19.75 KB      │ 19.75 KB      │         │
   │                 dealloc:      │               │               │               │         │
   │                   568         │ 541           │ 568           │ 567.7         │         │
   │                   28.7 KB     │ 27.84 KB      │ 28.7 KB       │ 28.69 KB      │         │
   │                 grow:         │               │               │               │         │
   │                   27          │ 27            │ 27            │ 27            │         │
   │                   8.952 KB    │ 8.952 KB      │ 8.952 KB      │ 8.952 KB      │         │
   ╰─ Rgb<u8>                      │               │               │               │         │
      ├─ FullBuffer  286.2 µs      │ 314.9 µs      │ 291.4 µs      │ 294.7 µs      │ 100     │ 100
      │              max alloc:    │               │               │               │         │
      │                2           │ 2             │ 2             │ 2.27          │         │
      │                464 B       │ 464 B         │ 464 B         │ 472.6 B       │         │
      │              alloc:        │               │               │               │         │
      │                565         │ 565           │ 565           │ 565           │         │
      │                19.42 KB    │ 19.42 KB      │ 19.42 KB      │ 19.42 KB      │         │
      │              dealloc:      │               │               │               │         │
      │                565         │ 565           │ 565           │ 564.7         │         │
      │                21.32 KB    │ 21.32 KB      │ 21.32 KB      │ 21.31 KB      │         │
      │              grow:         │               │               │               │         │
      │                16          │ 16            │ 16            │ 16            │         │
      │                1.904 KB    │ 1.904 KB      │ 1.904 KB      │ 1.904 KB      │         │
      ╰─ LineByLine  300.3 µs      │ 322.7 µs      │ 304 µs        │ 304.4 µs      │ 100     │ 100
                     max alloc:    │               │               │               │         │
                       5           │ 32            │ 5             │ 5.27          │         │
                       7.84 KB     │ 8.704 KB      │ 7.84 KB       │ 7.848 KB      │         │
                     alloc:        │               │               │               │         │
                       568         │ 568           │ 568           │ 568           │         │
                       19.75 KB    │ 19.75 KB      │ 19.75 KB      │ 19.75 KB      │         │
                     dealloc:      │               │               │               │         │
                       568         │ 541           │ 568           │ 567.7         │         │
                       28.7 KB     │ 27.84 KB      │ 28.7 KB       │ 28.69 KB      │         │
                     grow:         │               │               │               │         │
                       27          │ 27            │ 27            │ 27            │         │
                       8.952 KB    │ 8.952 KB      │ 8.952 KB      │ 8.952 KB      │         │

Master without this patch

Timer precision: 17 ns
bench                fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ full                            │               │               │               │         │
│  ├─ Rgb565Pixel    541.4 µs      │ 869.6 µs      │ 671 µs        │ 680.3 µs      │ 100     │ 100
│  │                 max alloc:    │               │               │               │         │
│  │                   390         │ 390           │ 390           │ 408.4         │         │
│  │                   43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 44.84 KB      │         │
│  │                 alloc:        │               │               │               │         │
│  │                   3057        │ 3057          │ 3057          │ 3057          │         │
│  │                   179 KB      │ 179 KB        │ 179 KB        │ 179 KB        │         │
│  │                 dealloc:      │               │               │               │         │
│  │                   3056        │ 3056          │ 3056          │ 3033          │         │
│  │                   203.6 KB    │ 203.6 KB      │ 203.6 KB      │ 202.3 KB      │         │
│  │                 grow:         │               │               │               │         │
│  │                   250         │ 250           │ 250           │ 250.2         │         │
│  │                   24.61 KB    │ 24.61 KB      │ 24.61 KB      │ 24.81 KB      │         │
│  ╰─ Rgb<u8>        919.1 µs      │ 1.373 ms      │ 1.09 ms       │ 1.097 ms      │ 100     │ 100
│                    max alloc:    │               │               │               │         │
│                      390         │ 390           │ 390           │ 390           │         │
│                      43.91 KB    │ 43.91 KB      │ 43.91 KB      │ 43.91 KB      │         │
│                    alloc:        │               │               │               │         │
│                      3057        │ 3057          │ 3057          │ 3057          │         │
│                      179 KB      │ 179 KB        │ 179 KB        │ 179 KB        │         │
│                    dealloc:      │               │               │               │         │
│                      3056        │ 3056          │ 3056          │ 3056          │         │
│                      203.6 KB    │ 203.6 KB      │ 203.6 KB      │ 203.6 KB      │         │
│                    grow:         │               │               │               │         │
│                      250         │ 250           │ 250           │ 250           │         │
│                      24.61 KB    │ 24.61 KB      │ 24.61 KB      │ 24.71 KB      │         │
╰─ render_only                     │               │               │               │         │
   ├─ Rgb565Pixel                  │               │               │               │         │
   │  ├─ FullBuffer  234.1 µs      │ 249.1 µs      │ 236.5 µs      │ 237.1 µs      │ 100     │ 100
   │  │              max alloc:    │               │               │               │         │
   │  │                2           │ 186           │ 2             │ 3.84          │         │
   │  │                464 B       │ 6.352 KB      │ 464 B         │ 522.8 B       │         │
   │  │              alloc:        │               │               │               │         │
   │  │                665         │ 665           │ 665           │ 665           │         │
   │  │                23.9 KB     │ 23.9 KB       │ 23.9 KB       │ 23.9 KB       │         │
   │  │              dealloc:      │               │               │               │         │
   │  │                665         │ 481           │ 665           │ 663.1         │         │
   │  │                27.37 KB    │ 21.48 KB      │ 27.37 KB      │ 27.31 KB      │         │
   │  │              grow:         │               │               │               │         │
   │  │                30          │ 30            │ 30            │ 30            │         │
   │  │                3.472 KB    │ 3.472 KB      │ 3.472 KB      │ 3.472 KB      │         │
   │  ╰─ LineByLine  244.2 µs      │ 275.3 µs      │ 248.8 µs      │ 249.9 µs      │ 100     │ 100
   │                 max alloc:    │               │               │               │         │
   │                   5           │ 5             │ 5             │ 6.84          │         │
   │                   7.84 KB     │ 7.84 KB       │ 7.84 KB       │ 7.898 KB      │         │
   │                 alloc:        │               │               │               │         │
   │                   668         │ 668           │ 668           │ 668           │         │
   │                   24.23 KB    │ 24.23 KB      │ 24.23 KB      │ 24.23 KB      │         │
   │                 dealloc:      │               │               │               │         │
   │                   668         │ 668           │ 668           │ 666.1         │         │
   │                   34.75 KB    │ 34.75 KB      │ 34.75 KB      │ 34.69 KB      │         │
   │                 grow:         │               │               │               │         │
   │                   41          │ 41            │ 41            │ 41            │         │
   │                   10.52 KB    │ 10.52 KB      │ 10.52 KB      │ 10.52 KB      │         │
   ╰─ Rgb<u8>                      │               │               │               │         │
      ├─ FullBuffer  322.4 µs      │ 337.2 µs      │ 324.2 µs      │ 325.3 µs      │ 100     │ 100
      │              max alloc:    │               │               │               │         │
      │                2           │ 2             │ 2             │ 3.84          │         │
      │                464 B       │ 464 B         │ 464 B         │ 522.8 B       │         │
      │              alloc:        │               │               │               │         │
      │                665         │ 665           │ 665           │ 665           │         │
      │                23.9 KB     │ 23.9 KB       │ 23.9 KB       │ 23.9 KB       │         │
      │              dealloc:      │               │               │               │         │
      │                665         │ 665           │ 665           │ 663.1         │         │
      │                27.37 KB    │ 27.37 KB      │ 27.37 KB      │ 27.31 KB      │         │
      │              grow:         │               │               │               │         │
      │                30          │ 30            │ 30            │ 30            │         │
      │                3.472 KB    │ 3.472 KB      │ 3.472 KB      │ 3.472 KB      │         │
      ╰─ LineByLine  337 µs        │ 358.9 µs      │ 341.2 µs      │ 342 µs        │ 100     │ 100
                     max alloc:    │               │               │               │         │
                       5           │ 5             │ 5             │ 6.84          │         │
                       7.84 KB     │ 7.84 KB       │ 7.84 KB       │ 7.898 KB      │         │
                     alloc:        │               │               │               │         │
                       668         │ 668           │ 668           │ 668           │         │
                       24.23 KB    │ 24.23 KB      │ 24.23 KB      │ 24.23 KB      │         │
                     dealloc:      │               │               │               │         │
                       668         │ 668           │ 668           │ 666.1         │         │
                       34.75 KB    │ 34.75 KB      │ 34.75 KB      │ 34.69 KB      │         │
                     grow:         │               │               │               │         │
                       41          │ 41            │ 41            │ 41            │         │
                       10.52 KB    │ 10.52 KB      │ 10.52 KB      │ 10.52 KB      │         │

…acker

This way we avoid rendering when only the layout is dirty but didn't
actually change
Since every renderer is now always clipping the text, we don't need to
account for out of bound drawing.

The other optimization of trying not to draw things if the bounding box
is smaller is not really a good one since computing the bounding box is
itself too expensive and not cached.
No chance we find something dirty there
It uses NaN in one of the coordinate.
It used to be fine because we would rely on the tracker to know if
anything had changed.
But now that we always compare the rectangle and NaN is always != NaN,
we would redraw too much for this test
@ogoffart ogoffart force-pushed the olivier/swrenderer branch from 804f731 to 8c5c28f Compare October 8, 2025 14:59
@ogoffart ogoffart requested a review from tronical October 8, 2025 16:13
@ogoffart ogoffart merged commit c0be4cd into master Oct 8, 2025
41 checks passed
@ogoffart ogoffart deleted the olivier/swrenderer branch October 8, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants