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

feat: Incremental rendering #811

Merged
merged 71 commits into from
Sep 7, 2024
Merged

feat: Incremental rendering #811

merged 71 commits into from
Sep 7, 2024

Conversation

marc2332
Copy link
Owner

@marc2332 marc2332 commented Aug 10, 2024

Closes #247

This PR adds incremental rendering support for Freya. Allowing to render only what has changed + what has been affected by the changes. This is a major improvement for rendering performance as Freya used to do full re-renders of the whole tree in every render frame, thus slowing down as the tree of nodes increased, even if only 1 small node changed.

To Do

  • Layout-based dirty area invalidation
  • Rotation-based dirty area invalidation
  • Border-based dirty area invalidation
  • Shadows-based (text included) dirty area invalidation
  • Incremental opacities and rotations inheritance
  • Enable parallel processing of style states in Nodes
  • Improved logging
  • Refactored the rendering pipeline
  • Research potential optimizations:
    • [ ] Consider viewports to reduce the dirty area
    • [ ] Use dashmap for hashmaps/hashsets currently wrapped in Arc<Mutex<T>>.
    • Ignore non-drawable Nodes when checking if they affect the dirty area
  • More unit tests
  • Clean up code

Findings

@marc2332 marc2332 added enhancement 🔥 New feature or request skia 🖌️ performance ⚡️ Performance improvement ⚡️ labels Aug 10, 2024
Copy link

Benchmark for 3b7aa99

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 109.2±0.63ms 110.4±0.27ms +1.10%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 25.4±0.94ms 25.6±1.52ms +0.79%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1490.7±12.96µs 1482.9±18.51µs -0.52%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 143.9±8.51µs 142.9±2.73µs -0.69%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.5±0.80ms 24.3±1.17ms -0.82%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1771.3±26.71µs 1740.0±12.23µs -1.77%
benchmarks/size=19531 depth=7 wide=5 mode=cached 313.1±4.06µs 311.5±3.93µs -0.51%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.7±0.02ms 2.7±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 428.3±132.95µs 426.2±129.06µs -0.49%
benchmarks/size=54241 depth=5 wide=15 mode=cached 251.9±117.68µs 243.9±10.79µs -3.18%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 7.1±0.19ms 6.8±0.39ms -4.23%

Copy link

codecov bot commented Aug 11, 2024

Codecov Report

Attention: Patch coverage is 74.57512% with 374 lines in your changes missing coverage. Please review.

Project coverage is 75.94%. Comparing base (4f3a046) to head (f607535).
Report is 72 commits behind head on main.

Files with missing lines Patch % Lines
crates/core/src/render/pipeline.rs 0.00% 157 Missing ⚠️
crates/renderer/src/app.rs 0.00% 46 Missing ⚠️
crates/testing/src/test_handler.rs 11.11% 24 Missing ⚠️
crates/core/src/elements/rect.rs 77.88% 23 Missing ⚠️
crates/renderer/src/renderer.rs 0.00% 18 Missing ⚠️
crates/renderer/src/window_state.rs 0.00% 15 Missing ⚠️
crates/core/src/render/compositor.rs 97.68% 12 Missing ⚠️
crates/core/src/render/skia_measurer.rs 78.18% 12 Missing ⚠️
crates/renderer/src/size.rs 0.00% 12 Missing ⚠️
crates/core/src/elements/paragraph.rs 90.67% 11 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #811      +/-   ##
==========================================
+ Coverage   75.14%   75.94%   +0.80%     
==========================================
  Files         201      202       +1     
  Lines       21664    22760    +1096     
==========================================
+ Hits        16279    17286    +1007     
- Misses       5385     5474      +89     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@marc2332
Copy link
Owner Author

better idea:

have a secondary canvas in which to render all the mutated layers with a clip of the affected area, and then just write the secondary canvas to the main

kinda inspired in vizia

Copy link

Benchmark for 9e5aaff

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 111.2±1.74ms 107.8±0.19ms -3.06%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 25.2±0.89ms 25.1±1.35ms -0.40%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1488.3±25.97µs 1514.8±129.19µs +1.78%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 142.5±4.01µs 144.2±0.93µs +1.19%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 25.8±0.34ms 24.5±0.78ms -5.04%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1758.1±9.74µs 1734.0±34.20µs -1.37%
benchmarks/size=19531 depth=7 wide=5 mode=cached 360.4±10.75µs 313.1±1.91µs -13.12%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.8±0.04ms 2.7±0.07ms -3.57%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 429.0±63.14µs 425.7±94.75µs -0.77%
benchmarks/size=54241 depth=5 wide=15 mode=cached 311.6±34.43µs 260.6±17.96µs -16.37%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.7±0.18ms 6.9±0.43ms +2.99%

Copy link

Benchmark for e8e8899

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 110.3±4.78ms 107.9±0.19ms -2.18%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.3±0.71ms 24.5±1.07ms +0.82%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1490.6±35.21µs 1467.7±10.31µs -1.54%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 142.3±1.91µs 141.7±2.34µs -0.42%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.3±0.87ms 23.8±0.19ms -2.06%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1749.2±81.93µs 1720.3±4.61µs -1.65%
benchmarks/size=19531 depth=7 wide=5 mode=cached 309.5±2.32µs 308.1±1.60µs -0.45%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.7±0.02ms 2.7±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 426.7±101.83µs 425.7±130.52µs -0.23%
benchmarks/size=54241 depth=5 wide=15 mode=cached 245.2±8.57µs 242.2±8.98µs -1.22%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.6±0.04ms 6.6±0.04ms 0.00%

@marc2332 marc2332 changed the title feat: WIP Incremental rendering feat: Incremental rendering Aug 14, 2024
Copy link

Benchmark for cd97ed5

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 111.9±0.52ms 114.2±4.42ms +2.06%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 26.8±0.77ms 29.4±1.16ms +9.70%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1520.6±117.54µs 1601.7±149.53µs +5.33%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 144.0±1.31µs 144.3±2.58µs +0.21%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 25.4±0.47ms 27.7±0.81ms +9.06%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1750.7±10.21µs 2.4±0.30ms +37.09%
benchmarks/size=19531 depth=7 wide=5 mode=cached 366.4±24.09µs 379.5±15.97µs +3.58%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.8±0.04ms 3.4±0.28ms +21.43%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 421.6±26.34µs 427.3±58.39µs +1.35%
benchmarks/size=54241 depth=5 wide=15 mode=cached 312.6±21.66µs 414.5±41.37µs +32.60%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 7.0±0.49ms 8.0±0.48ms +14.29%

Copy link

Benchmark for 31ece18

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 109.6±0.57ms 109.2±0.61ms -0.36%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 25.5±0.99ms 26.4±1.61ms +3.53%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1480.5±12.01µs 1468.1±22.92µs -0.84%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 141.6±1.40µs 141.2±1.49µs -0.28%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.9±0.94ms 24.3±0.63ms -2.41%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1746.0±6.38µs 1733.4±7.25µs -0.72%
benchmarks/size=19531 depth=7 wide=5 mode=cached 315.8±7.40µs 323.9±16.79µs +2.56%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.7±0.05ms 2.7±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 430.5±151.25µs 430.3±147.28µs -0.05%
benchmarks/size=54241 depth=5 wide=15 mode=cached 251.1±18.79µs 254.6±16.19µs +1.39%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.8±0.55ms 6.6±0.12ms -2.94%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for 2ca95c5

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 108.1±0.66ms 108.8±1.94ms +0.65%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 26.2±0.73ms 25.7±1.11ms -1.91%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1441.1±13.88µs 1433.9±17.86µs -0.50%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 138.4±1.59µs 137.0±2.22µs -1.01%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.8±0.71ms 24.5±0.80ms -1.21%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1770.5±76.60µs 1725.5±53.49µs -2.54%
benchmarks/size=19531 depth=7 wide=5 mode=cached 344.9±30.48µs 363.0±33.78µs +5.25%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.7±0.13ms 2.7±0.10ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 418.1±133.14µs 417.5±103.52µs -0.14%
benchmarks/size=54241 depth=5 wide=15 mode=cached 328.4±64.48µs 303.1±59.10µs -7.70%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.8±0.42ms 6.7±0.45ms -1.47%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for fa23858

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 106.1±0.33ms 105.2±0.51ms -0.85%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.4±0.63ms 24.2±0.83ms -0.82%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1430.1±12.41µs 1406.4±9.79µs -1.66%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 137.0±0.73µs 135.0±2.10µs -1.46%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 23.5±0.30ms 23.6±0.38ms +0.43%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1688.2±32.25µs 1683.0±65.25µs -0.31%
benchmarks/size=19531 depth=7 wide=5 mode=cached 312.1±3.63µs 306.5±2.38µs -1.79%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.01ms 2.6±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 413.5±132.24µs 411.1±128.50µs -0.58%
benchmarks/size=54241 depth=5 wide=15 mode=cached 248.3±7.17µs 244.0±9.60µs -1.73%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.18ms 6.4±0.07ms 0.00%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for 38cfa4e

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 105.2±0.51ms 117.9±0.62ms +12.07%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.4±0.61ms 25.0±0.99ms +2.46%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1421.9±16.61µs 1433.7±38.17µs +0.83%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 137.6±0.99µs 138.2±0.91µs +0.44%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.2±0.39ms 24.2±0.38ms 0.00%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1686.7±40.85µs 1706.6±13.73µs +1.18%
benchmarks/size=19531 depth=7 wide=5 mode=cached 314.5±10.40µs 311.9±4.79µs -0.83%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.02ms 2.6±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 411.2±132.61µs 413.2±128.46µs +0.49%
benchmarks/size=54241 depth=5 wide=15 mode=cached 262.1±27.78µs 249.4±11.68µs -4.85%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.09ms 6.4±0.06ms 0.00%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for 15145cb

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 108.5±0.41ms 105.0±0.52ms -3.23%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.4±0.41ms 24.2±0.75ms -0.82%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1410.6±12.36µs 1430.5±18.99µs +1.41%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 137.5±1.44µs 135.3±1.27µs -1.60%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 23.8±0.60ms 24.3±1.09ms +2.10%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1693.5±33.68µs 1723.0±104.35µs +1.74%
benchmarks/size=19531 depth=7 wide=5 mode=cached 316.9±8.58µs 313.9±6.61µs -0.95%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.01ms 2.6±0.02ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 412.9±76.09µs 411.8±119.37µs -0.27%
benchmarks/size=54241 depth=5 wide=15 mode=cached 250.9±14.77µs 255.2±18.98µs +1.71%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.23ms 6.4±0.18ms 0.00%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for 48c3b0a

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 107.7±1.53ms 106.5±0.98ms -1.11%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.5±1.02ms 24.3±1.30ms -0.82%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1435.9±18.15µs 1424.5±34.32µs -0.79%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 138.1±1.50µs 137.6±2.63µs -0.36%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.2±0.77ms 23.5±0.63ms -2.89%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1697.0±22.40µs 1720.9±50.69µs +1.41%
benchmarks/size=19531 depth=7 wide=5 mode=cached 324.9±25.80µs 317.1±11.21µs -2.40%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.10ms 2.6±0.13ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 419.1±134.05µs 420.6±128.87µs +0.36%
benchmarks/size=54241 depth=5 wide=15 mode=cached 268.4±45.80µs 270.8±42.20µs +0.89%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.25ms 6.5±0.27ms +1.56%

Copy link

github-actions bot commented Sep 1, 2024

Benchmark for 452e045

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 105.1±0.45ms 106.0±0.63ms +0.86%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.5±0.47ms 24.3±0.97ms -0.82%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1432.5±17.26µs 1435.6±103.86µs +0.22%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 136.4±5.77µs 139.8±12.15µs +2.49%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.0±0.32ms 24.1±0.34ms +0.42%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1678.7±9.60µs 1688.1±31.13µs +0.56%
benchmarks/size=19531 depth=7 wide=5 mode=cached 315.4±4.56µs 309.6±2.79µs -1.84%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.02ms 2.6±0.01ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 416.4±187.89µs 418.1±130.01µs +0.41%
benchmarks/size=54241 depth=5 wide=15 mode=cached 246.8±11.13µs 246.1±11.65µs -0.28%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.07ms 6.4±0.38ms 0.00%

@marc2332
Copy link
Owner Author

marc2332 commented Sep 2, 2024

⚠️ to do:

  • test svgs that have a fixed size
  • deterministic order of rendering for nodes in each layer by sorting them based on their node id

@marc2332 marc2332 marked this pull request as ready for review September 7, 2024 18:52
Copy link

github-actions bot commented Sep 7, 2024

Benchmark for acd6364

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 103.4±0.86ms 103.1±3.39ms -0.29%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.6±0.45ms 25.6±1.28ms +4.07%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1416.7±18.88µs 1400.7±13.41µs -1.13%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 134.6±1.50µs 137.0±5.50µs +1.78%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 24.6±0.31ms 24.7±0.48ms +0.41%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1748.5±41.38µs 1711.3±7.66µs -2.13%
benchmarks/size=19531 depth=7 wide=5 mode=cached 329.4±26.41µs 312.8±2.56µs -5.04%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.04ms 2.6±0.02ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 416.9±133.09µs 420.0±78.19µs +0.74%
benchmarks/size=54241 depth=5 wide=15 mode=cached 281.4±95.02µs 273.4±130.57µs -2.84%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.20ms 6.4±0.19ms 0.00%

Copy link

github-actions bot commented Sep 7, 2024

Benchmark for 8fa60d8

Click to view benchmark
Test Base PR %
benchmarks/alignments=true size=21845 depth=8 wide=4 mode=not cached 102.4±0.61ms 101.9±0.53ms -0.49%
benchmarks/size=100001 depth=2 wide=100000 mode=not cached 24.7±0.54ms 24.5±0.75ms -0.81%
benchmarks/size=10001 depth=2 wide=10000 mode=not cached 1403.3±8.80µs 1394.8±38.11µs -0.61%
benchmarks/size=1001 depth=2 wide=1000 mode=not cached 136.7±2.01µs 134.8±1.14µs -1.39%
benchmarks/size=131071 depth=17 wide=2 mode=not cached 23.7±0.37ms 23.7±0.32ms 0.00%
benchmarks/size=16383 depth=14 wide=2 mode=not cached 1694.8±11.72µs 1690.2±15.57µs -0.27%
benchmarks/size=19531 depth=7 wide=5 mode=cached 316.9±4.39µs 312.3±11.36µs -1.45%
benchmarks/size=19531 depth=7 wide=5 mode=not cached 2.6±0.02ms 2.6±0.02ms 0.00%
benchmarks/size=4095 depth=12 wide=2 mode=not cached 413.4±114.65µs 410.6±74.05µs -0.68%
benchmarks/size=54241 depth=5 wide=15 mode=cached 254.3±15.92µs 250.6±12.59µs -1.45%
benchmarks/size=54241 depth=5 wide=15 mode=not cached 6.4±0.33ms 6.4±0.10ms 0.00%

@marc2332 marc2332 merged commit 630a579 into main Sep 7, 2024
5 checks passed
@marc2332 marc2332 deleted the feat/incremental-rendering branch September 7, 2024 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request performance ⚡️ Performance improvement ⚡️ skia 🖌️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enhancement: Incremental rendering
1 participant