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

The ScrollView has a high CPU load when the scrollbar appears #5476

Open
TuEmb opened this issue Jun 25, 2024 · 9 comments
Open

The ScrollView has a high CPU load when the scrollbar appears #5476

TuEmb opened this issue Jun 25, 2024 · 9 comments

Comments

@TuEmb
Copy link

TuEmb commented Jun 25, 2024

I'm using ScrollView and VerticalLayout to display my data, the CPU load is acceptable (~11%) when displaying just enough data to fit on the screen without needing a scrollbar. However, when I add more data and the scrollbar appears, the CPU load increases significantly (>50%). After that, I expand my window app, the scrollbar disappears and the CPU load goes down again.

I'm using Slint with Rust. You can find my source code here: https://github.com/TuEmb/can-viewer
Here is my record for this bug:

can-viewer.webm
@ogoffart
Copy link
Member

thanks for reporting an issue. I have checked out your code, but i am not sure how to load data. Could you guide me on how to import data so i can reproduce the problem?

Otherwise, one thing to try to figure out where the problem is is to run a profiler such as valgrind or perf to find out what is taking CPU time. Btw, is it a release or debug build?
You can also see if there is a difference between the skia or the femtovg renderer.

@TuEmb
Copy link
Author

TuEmb commented Jun 25, 2024

Thanks for your reply, I built my code with release. I used femtovg and software renderer and the results are below pictures:

image
image

For skia renderer, I'm having the issue out of memory. So that I can't test with skia renderer now. I will try to use skia renderer later.
image

Step to run my source code with a simulation data:

  1. you can create a virtual can socket on Ubuntu OS: https://www.pragmaticlinux.com/2021/10/how-to-create-a-virtual-can-interface-on-linux/#google_vignette

  2. Then update my code to use "vcan0" instead of "can0" at https://github.com/TuEmb/can-viewer/blob/a58a3fdc4b60192f19abf020896190a66ecec426/src/main.rs#L29

  3. you can download my material here, then run the software --> open --> choose to "can_db.dbc"
    can-viewer-simulate.zip

  4. Finally you can run the script "vcan_loop.sh" to simulate CAN data

@ogoffart
Copy link
Member

I think this is probably the same as #5041
Can you try disabling accessibility by tweaking the features of slint?

@TuEmb
Copy link
Author

TuEmb commented Jun 26, 2024

I updated the features in my project to:

slint = { version = "1.6.0", default-features = false, features = ["backend-winit", "compat-1-2", "renderer-winit-femtovg"] }

But the issue is still there

@TuEmb
Copy link
Author

TuEmb commented Jun 26, 2024

I used the valgrind to do profiling my app, but I have no experiment in reading this file. Could you help me find out what the problems are ?
callgrind.out.zip

I used callgrind to open this file:

image

@TuEmb
Copy link
Author

TuEmb commented Jun 26, 2024

After looking through all data I have, It seems when we use scroll view with un-fixed value of viewport-width and viewport-height, It has to allocate and deallocate a lot of time for redrawing. Because in my application, the elements inside ScrollView are flexible. I updated the ScrollView with fixed value, it seems the CPU load reduced a lot.

From the documentation, also mention about the loop inside ScrollView is not fully supported now: https://releases.slint.dev/1.6.0/docs/slint/src/language/widgets/scrollview.html

I'm looking forward to having this feature in Slint soon. Thanks for your response

image

@ogoffart
Copy link
Member

Perhaps you can try to use a ListView instead of a ScrollView?

@ogoffart
Copy link
Member

Regarding the way to use kcachegrind, i like to watch at the "Call Graph" tab and go to find which subtree is taking lots of instructions. Also you get better result by unchecking the "Cycle Detection" in the toolbar.

@TuEmb
Copy link
Author

TuEmb commented Jun 27, 2024

Thank @ogoffart,

It seems my application works more stable when I use ListView, But I got a problem with scrollbar. If I use the mouse hold the scrollbar and move up/down, the animation goes crazy.

ListView.webm

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

No branches or pull requests

2 participants