slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.71k stars 614 forks source link

Why is the CPU usage so high when clicking a button? #4782

Open nczyw opened 8 months ago

nczyw commented 8 months ago

slint::slint!{ import { Button , VerticalBox } from "std-widgets.slint"; export component App inherits Window { in property <int> counter:0; callback clicked <=> bb.clicked; VerticalBox { Text {text: "Hello world " + counter; font-size: 50px;} bb := Button { text: "按钮如何调整大小"; width: 500px; height: 500px; } } } } The above is my testing code. Whenever I click the button, the CPU spikes to over 30%. Also, how to adjust the font size of the button?

nczyw commented 8 months ago

slint_cpu

ansarizafar commented 8 months ago

CPU usage is 100% when you just run basic Slint app with latest nightly version and Nodejs/Bunjs/Deno on Ubuntu.

nczyw commented 8 months ago

CPU usage is 100% when you just run basic Slint app with latest nightly version and Nodejs/Bunjs/Deno on Ubuntu. Oh my god ,i originally planned to use slint instead of Qt to write industrial software, but it seems that it is not feasible yet.

ogoffart commented 8 months ago

@nczyw I've tried to run this app and it is not taking particularily lot of CPU.

Are you using in release or debug mode. Make sure you are running with --release. What renderer are you using? The default is the femtovg renderer, but you might want to try the skia renderer for better performance.

@ansarizafar That's probably another issue. Do you know what is causing it?

ansarizafar commented 8 months ago

@ogoffart I don't what causing it but two CPU cores are constantly on 100%.

nczyw commented 8 months ago

@nczyw I've tried to run this app and it is not taking particularily lot of CPU.

Are you using in release or debug mode. Make sure you are running with --release. What renderer are you using? The default is the femtovg renderer, but you might want to try the skia renderer for better performance.

@ansarizafar That's probably another issue. Do you know what is causing it?

I'm using --release I'm very sorry, I just started using slint and don't know how to switch skia renderer.

nczyw commented 8 months ago

This happens only when the button is clicked all the time. CPU usage is 0% when not clicking the button

tronical commented 8 months ago

Thank you for your report. Could you also show us the code that's invoked when you press the button, i.e. when the clicked callback is invoked?

nczyw commented 8 months ago

Thank you for your report. Could you also show us the code that's invoked when you press the button, i.e. when the clicked callback is invoked?

Ok. `fn main() { // let _handle = web_server(); println!("多线程异步web测试"); let app = App::new().unwrap(); let weak = app.as_weak(); app.on_clicked(move || { let app = weak.upgrade().unwrap(); app.set_counter(app.get_counter() + 2); }); app.run().unwrap(); }

slint::slint!{ import { Button , VerticalBox } from "std-widgets.slint"; export component App inherits Window { in property counter:0; callback clicked <=> bb.clicked; VerticalBox { Text {text: "Hello world " + counter; font-size: 50px;} bb := Button { text: "按钮如何调整大小"; width: 500px; height: 500px; } } } }` The above is the complete code. The code comes from the demo in your YouTube tutorial.

ogoffart commented 5 months ago

I have no idea what's going on on your machine. Would you be able to use a profiler to find out what's taking CPU?