knaeckeKami / changenotifier_benchmark

15 stars 3 forks source link

Measure memory consumption #7

Open tlvenn opened 3 years ago

tlvenn commented 3 years ago

When looking at the benchmark, we focus essentially on performance on the scale of how fast we can notify listeners but on constrained devices like mobiles, especially when you are trying to target as many of them and not just the latest generation, memory footprint is essential.

I was wondering if there is any way to measure and compare this between solutions ? I did not look into the implementations but it's common that one way to speed up things is to memoize / index and it usually come at the expense of memory so while one solution might be faster than another it might put too much pressure on the memory.

Just trying to open the conversation and see what is the general consensus on this subject. I believe I read that the author of getx was particularly surprised to notice how much memory the default stream implementation is consuming for example and that was what probably motivated him to develop some alternate stream solutions.

knaeckeKami commented 3 years ago

Yeah, good point. I actually think that the fastest approaches are also the ones with the smallest memory footprint, as they are fast because they avoid unnecessary copies (compared to the ValueNotifier in Flutter) and use compact data structures like arrays instead of linked lists.

But you are right, we should also profile that.

letsar commented 3 years ago

I tried to profile this with DartDev Tools but I only get the size of the pointers :/ I will search it we can have some kind of method which can gives us the total consumed memory at a time

knaeckeKami commented 3 years ago

@letsar added a Flutter app to measure to footprint in DevTools. As expected, the proposed version has a much smaller footprint than the current one (Due to the usage of default ArrayLists instead of linked lists and due to the omission of the _Listener wrapper objects).

Unfortunately, we did not find a way to automate measuring the memory footprint.

tlvenn commented 3 years ago

Good to hear and confirm. I had a look at the packages from devtools, it's too bad that they did not separate the client from the app itself, it would had probably made this exercise possible without too much effort.