DEV Community

Jayson Ragasa
Jayson Ragasa

Posted on

Clear Add VS Lookup Move


GitHub Repo

Clear Add VS Lookup Move

It's always in my thought but barely implemented that when just refreshing the list to show updated data or just sorting things. It's always better to move the items around instead of calling .Clear() then refilling the list. I implemented this before, way back 2015 when I was working on a Kiosk WPF app and in administration mode there are some lists that shows real time updates.. it's a pain watching the list clearing and then repopulating when something changes in the background. It's ugly, it's slow, and you can't click on it.

I am working on a simple project called COVID19 Tracker were I need to sort different columns of COVID19 cases -- Country, Confirmed Case, Total Recoveries, Total Deaths. When I click on the column headers, I noticed this very slow performance when repopulating the ListView and it even got slower when the hot reload triggers the refresh of the entire page.

Look at the duration here

The ListView is bound on an ObservableCollection<T> and has 221 items in it. We're not paging for the mean time. I also have a List<T> where I keep a backup for sorting purposes. So comparing the result of usinig lazy reloading were we use .Clear() and .Add(T) to refresh the items in the list against just moving the items T LookupItem() and .Move(int index). The result is interesting.

  • Lazy loading took 100 to 130 +- millisecond to complete EVERYTIME I sort the list
  • Moving took only 20 to 30 +- millisecond. That's a huge difference in performance. Codes may be a bit longer with this one plus the look up is using .Where. I think it may perform even more faster if I used the traditional loop.

This duration will be different of course based on your device. In my device, the lazy load took 300+- ms and using Move took only around 60+-ms.

iOS List Animation

Here's the difference in iOS.



Left simulator is "filling" the list whilst the right is "switching". Please bear with the responses when activing the simulator. I am only using a virtual OS of the macOS High Sierra version 10.13.6
]

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

Collapse
 
jarafpv profile image
Jayson Ragasa

and I am not sure the iOS preview is not showing here but it's working in GitHub

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay