slint-ui / slint

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

List performance Problem #4097

Closed jerrygou007 closed 9 months ago

jerrygou007 commented 9 months ago

thank u for you guys to bring slint to the world.

we use rust+slint to build the software for windows

in our case, we have a page to show chat sessions, supported by a slint listview, it looks like below. everytime,when the new word is added to the screen (to the end of 4th item), the whole page will badly flicker,especially when the content is more than one page screen.

image

the list is updated by the below code

rust let datas_model: std::rc::Rc<slint::VecModel<ChatItemData>> = std::rc::Rc::new(slint::VecModel::from(datas)); ui.global::<Chat>().set_datas(datas_model.into());

slint ` chat-lv := ListView { for data in Chat.datas : ListViewItem { id: data.id; head: data.head; name: data.name; content: data.content; score: data.score; } visible: Chat.datas.length > 0; viewport-y: -self.viewport-height; } export global Chat { in-out property <[ChatItemData]> datas: [ ]; }

`

i dive into the slint source cod,bug there is no way for me to improve the performace, is there any suggestion for me to fix it. if the low performace is fact, hope you slint team can fix it. the listview xp is usually the most important thinking point for us to choose a UI Framework.

FloVanGH commented 9 months ago

Hi,

thank you for your report.

ui.global::<Chat>().set_datas(datas_model.into());

It this the way you update the model if there are changes or is this only initial?

If you use that way to update the model, it will be reloaded completely each time what ends up in a bad performance.

What you can do instead is this:

data_model.push(ChatItemData { ... });

This updates the view only on the position of the new item.

If you want to change data on a specific position you can do this:

data_model.set_row_data(3, ChatItemData { ... });

I hope this will help you. Otherwise feel free to ask for more help any time.