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

performance issue with svg icon in qt Buttons #7511

Open
djobet opened this issue Feb 1, 2025 · 5 comments
Open

performance issue with svg icon in qt Buttons #7511

djobet opened this issue Feb 1, 2025 · 5 comments
Labels
a:backend-qt The Qt backend - including the qt style (mO,bS) bug Something isn't working optimization

Comments

@djobet
Copy link

djobet commented Feb 1, 2025

Bug Description

I noticed my application was suddenly noticeably slower, so I bisected my repo.
This is the culprit :

david@grogu:~/dev/rust/pgn_viewer$ git show 36fe48c5690bbed9adf2f8c7efe795dc3628d5ee | cat
commit 36fe48c5690bbed9adf2f8c7efe795dc3628d5ee
Author: David Jobet <[email protected]>
Date:   Sat Feb 1 15:12:17 2025 +0000

    impl move with buttons

diff --git a/ui/move_tree.slint b/ui/move_tree.slint
index 0fb0ee1..0e1775d 100644
--- a/ui/move_tree.slint
+++ b/ui/move_tree.slint
@@ -38,6 +38,11 @@ export global MoveTreeModel {
 
     in property <image> load_image: @image-url("data/filesystem/folder-open.svg");
     in property <image> save_image: @image-url("data/filesystem/save.svg");
+    in property <image> prev_move: @image-url("data/move/chevron-back-outline.svg");
+    in property <image> next_move: @image-url("data/move/chevron-forward-outline.svg");
+    in property <image> prev_subline: @image-url("data/move/chevron-up.svg");
+    in property <image> next_subline: @image-url("data/move/chevron-down.svg");
+    in property <image> open_sublines: @image-url("data/move/caret-down-outline.svg");
 
     in property <[TreeChessMoves]> chess_moves: [];
     in property <TreePath> current_path : {path:[0], move_id: 1}; // TODO : should be init by rust
@@ -194,5 +197,37 @@ export component MoveTree inherits Rectangle {
                 }
             }
         }
+        HorizontalLayout {
+            Button {
+                icon: MoveTreeModel.prev_move;
+                clicked => {
+                    MoveTreeModel.keyboard_command(KeyboardCommand.Back);
+                }
+            }
+            Button {
+                icon: MoveTreeModel.next_move;
+                clicked => {
+                    MoveTreeModel.keyboard_command(KeyboardCommand.Next);
+                }
+            }
+            Button {
+                icon: MoveTreeModel.open_sublines;
+                clicked => {
+                    MoveTreeModel.keyboard_command(KeyboardCommand.OpenSublines);
+                }
+            }
+            Button {
+                icon: MoveTreeModel.prev_subline;
+                clicked => {
+                    MoveTreeModel.keyboard_command(KeyboardCommand.PrevSubline);
+                }
+            }
+            Button {
+                icon: MoveTreeModel.next_subline;
+                clicked => {
+                    MoveTreeModel.keyboard_command(KeyboardCommand.NextSubline);
+                }
+            }
+        }
     }
 }

With this commit reverted, everything is smooth again.
See attached videos
smooth one : (with revert) https://github.com/user-attachments/assets/68a52bb9-515c-40da-bdac-f055295e4d51
choppy one : https://github.com/user-attachments/assets/2431a602-2830-4a3f-a222-3ba36d700bf5

At that point, I'm not sure how I can make a minimal example, but I can give you the full code if you want.

Note : no regression with SLINT_BACKEND=winit
Note : for some reason I could not upload a tgz of my git repo

Reproducible Code (if applicable)

Environment Details

  • Slint Version: 1.9.1
  • Platform/OS: Linnux Fedora 41
  • Programming Language: rust
  • Backend/Renderer: qt

Product Impact

No real impact for me, but I thought you might be interested in tracking that regression.

@djobet djobet added bug Something isn't working need triaging Issue that the owner of the area still need to triage labels Feb 1, 2025
@ogoffart
Copy link
Member

ogoffart commented Feb 3, 2025

Looks like a bug indeed.
It could be that this code triggers some bad condition in the backend.
Looking at the change, it is perhaps a SVG that is slow to decode, or trashes the cache or something.
We would need to run a profiler to figure out.
If you give us a link to the reprository so i can try it out, I could try to investigate.

@ogoffart ogoffart added needs info Further information from the reporter is requested a:backend-qt The Qt backend - including the qt style (mO,bS) and removed need triaging Issue that the owner of the area still need to triage labels Feb 3, 2025
@djobet
Copy link
Author

djobet commented Feb 3, 2025 via email

@djobet
Copy link
Author

djobet commented Feb 3, 2025

Here's a quick repro (don't know if it would impact my chess pieces moving), but it definitively impact another dialog


export struct GameHeader {
    name: string,
    value: string,
}

export component SlowDisplay inherits Window {
    in property <image> new_image: @image-url("data/add-outline.svg");
    in property <image> delete_image: @image-url("data/trash.svg");

    property <[GameHeader]> headers: [
        {name: "White", value: "toto"},
        {name: "Black", value: "titi"}
    ];

    VerticalBox {
        ListView {
            for header in headers : HorizontalLayout {
                width: 300px;
                spacing: 5px;
                // Button {
                //     icon: delete_image;
                // }
                LineEdit {
                    text: header.name;
                    width: 100px;
                    edited(t) => {
                        header.name = t
                    }
                }
                LineEdit {
                    text: header.value;
                    width: 100px;
                    edited(t) => {
                        header.value = t
                    }
                }
            }
        }
    }
}

try uncommenting the button which has the delete_image and see the difference.
trash.svg can be downloaded from https://iconduck.com/icons/58973/trash

@ogoffart ogoffart added need triaging Issue that the owner of the area still need to triage and removed needs info Further information from the reporter is requested need triaging Issue that the owner of the area still need to triage labels Feb 5, 2025
@ogoffart
Copy link
Member

ogoffart commented Feb 6, 2025

I can reproduce the problem

@ogoffart
Copy link
Member

ogoffart commented Feb 6, 2025

I profiled in debug mode (because i could reproduce the problem better in debug)
Image
Looks like we re-render the SVG on every paint.

When drawing a Image in QtItemRenderer::draw_image_impl the result of image_to_pixmap is cached. But this is not the case when drawing a Button.

@ogoffart ogoffart changed the title performance regression when adding a new row of buttons with Qt renderer performance issue with svg icon in qt Buttons Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:backend-qt The Qt backend - including the qt style (mO,bS) bug Something isn't working optimization
Projects
None yet
Development

No branches or pull requests

2 participants