natinusala / borealis

Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx)
Apache License 2.0
257 stars 81 forks source link

Implement recycling views #118

Open natinusala opened 3 years ago

natinusala commented 3 years ago

When you have 200+ games on your Switch and you try to use the sys-clk manager, the framerate is down the toilets and RAM usage is up to the roof. That is because 200+ list items are allocated and drawn (they are clipped when out of view, but still), with each list item its own thumbnail.

To solve that problem, we need to implement the same recycling mechanism as Android has:

image Image credit to https://alexdunndev.files.wordpress.com/

This works best if all views in the list are the same.

Here's how to implement it in borealis:

The user is responsible for handling resources in the adapter code. If there are images to load for instance, they have to be unloaded in the "throw away" method, and loaded back in the "bind data" method. It can even be asynchronous if loading the image takes time (provided the Image class allows it 👀 ).

Or the implementation can be naive and everything can be stored in one big std::vector... in which case the framerate will stay fast, but the memory usage will be high. That's up to the user.

natinusala commented 3 years ago

In progress via #153