Skip to content

Performance fixes for larger files#1462

Open
Doublonmousse wants to merge 20 commits into
flxzt:mainfrom
Doublonmousse:performance
Open

Performance fixes for larger files#1462
Doublonmousse wants to merge 20 commits into
flxzt:mainfrom
Doublonmousse:performance

Conversation

@Doublonmousse

Copy link
Copy Markdown
Collaborator

Fixes #1436
(and maybe #1438, waiting on a response)

  • use push_repeat for background nodes : This seems to reduce RAM usage and buffer uploads to the gpu so there's more headroom for the rest of the nodes
  • use the rtree to speed up regenerate_rendering_in_viewport_threaded : We use the rtree to get the strokes in the viewport without recalculating any stroke bounds, and get the ones not in the view by iterating on keys and using a hashmap to filter out the previously selected ones

On that subject, it seems we could use a https://docs.rs/slotmap/1.0.7/slotmap/sparse_secondary/struct.SparseSecondaryMap.html for the render components and/or be smarter on clearing the render_comp components of strokes (we know there's no work to do if we have x strokes in view that we just initialized the rendering components and x strokes in the rendering component slot)

I've updated the rtree to only keep bounds for visible strokes (so trashed strokes are removed from the tree)

I've also added to the visual debug mode a way to see the envelope of the whole rtree (marked by orange bounds)

@Doublonmousse Doublonmousse added the performance Related to app performance label Jun 8, 2025

@flxzt flxzt left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

when this lands these are nice improvements to the rendering part of the engine. I added some comments

Comment thread crates/rnote-compose/src/ext.rs Outdated
Comment thread crates/rnote-engine/src/store/keytree.rs Outdated
Comment thread crates/rnote-engine/src/store/keytree.rs Outdated
Comment thread crates/rnote-engine/src/store/render_comp.rs Outdated
Comment thread crates/rnote-engine/src/store/render_comp.rs Outdated
Comment thread crates/rnote-engine/src/store/render_comp.rs Outdated
Comment thread crates/rnote-engine/src/store/mod.rs Outdated
Comment thread crates/rnote-engine/src/engine/rendering.rs Outdated
Comment thread crates/rnote-engine/src/engine/rendering.rs Outdated
Comment thread crates/rnote-engine/src/engine/mod.rs Outdated
@flxzt

flxzt commented Jun 28, 2025

Copy link
Copy Markdown
Owner

Only storing non-trashed strokes in the R-Tree is problematic and will require additional changes in other parts - essentially everywhere where one of the methods of KeyTree are used (like keys_in_bounds(), keys_intersecting_bounds() etc. Right now they are all used under the assumption that all strokes are included in the tree. Did you consider this?

Comment thread crates/rnote-engine/src/store/stroke_comp.rs Outdated
@Doublonmousse Doublonmousse marked this pull request as draft June 29, 2025 11:56
Comment thread crates/rnote-engine/src/store/render_comp.rs Outdated
@Doublonmousse

Copy link
Copy Markdown
Collaborator Author

I'm trying to rely more on the keytree to get stroke bounds whenever possible (as calculating a bunch of stroke bounds on each event is potentially pretty expensive).

Testing the two keytree solution, I'm encountering quite weird results with the splitting eraser

@Intranox

This comment was marked as off-topic.

@flxzt

flxzt commented Sep 23, 2025

Copy link
Copy Markdown
Owner

good to know, but not really relevant for the technical discussion this PR should focus on @Intranox

@Doublonmousse Doublonmousse self-assigned this Jan 3, 2026
@Doublonmousse Doublonmousse marked this pull request as ready for review January 4, 2026 17:00
@Doublonmousse

Copy link
Copy Markdown
Collaborator Author

Rebased on main.

New thing: opening the visual debug panel triggers the following message:

*** BUG ***
In pixman_region32_init_rect: Invalid rectangle passed
Set a breakpoint on '_pixman_log_error' to debug

Seems to be caused by the rectangle holding the statistics. Not sure if this is from this PR or not (maybe since a specific gtk version? Found https://github.com/fpaquet/gtksheet/pull/21/files and https://gitlab.gnome.org/GNOME/gtk/-/issues/6338)
There's probably more performance stuff to do but I'll leave it for other potential PRs.

Comment thread crates/rnote-engine/src/store/render_comp.rs Outdated
@Doublonmousse

Copy link
Copy Markdown
Collaborator Author

Rebased onto 0.14.2

@Doublonmousse Doublonmousse marked this pull request as ready for review May 14, 2026 20:47
This diminishes the cost for this
- one element of somewhat fixed size (no vec pushing)
- one element given to gtk that can tile this as it pleases with less buffer pushes
We use the rtree to find the element in the viewport, mark these ones using a hashmap, call the rendering function, then remove the rest by iterating on the keys a second time, filtering on keys not in the hashmap
Do not leak key trees out of the store structure
@Doublonmousse Doublonmousse marked this pull request as draft June 7, 2026 19:48
@Doublonmousse Doublonmousse marked this pull request as ready for review June 7, 2026 20:15
@Doublonmousse

Copy link
Copy Markdown
Collaborator Author

Rebased after #1776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Related to app performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance degrades on larger files

3 participants