TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8k stars 1.29k forks source link

RFC: Consider using dispatch memory warning functionality. #197

Open garrettmoon opened 7 years ago

garrettmoon commented 7 years ago

From @appleguy on March 1, 2017 3:0

It supports different levels of warning, and is also available on Mac OS X.

https://gist.github.com/steipete/33af275cc1cb419b0f01

We've considered this before, but it seems worth making the leap even if a straight port of existing NSNotifications. Also fine to just close this out if there aren't too many perceived advantages.

cc @garrettmoon @Adlai-Holler @maicki

Copied from original issue: facebookarchive/AsyncDisplayKit#3109

garrettmoon commented 7 years ago

From @Adlai-Holler on March 1, 2017 18:30

Good call! NSCache/libcache uses this to drive its eviction.

Seems like low cost & low benefit to me at this time – the cost is a couple lines of code, the benefit is slightly (negligibly?) improved performance and space for future enhancements. Since UIApplicationDidReceiveMemoryWarning is working well, I would endorse a diff if it didn't add too much complexity.

garrettmoon commented 7 years ago

From @maicki on March 1, 2017 19:12

@Adlai-Holler How does NSCache/libcache use this to drive the eviction, so in what level do they what?

garrettmoon commented 7 years ago

From @Adlai-Holler on March 1, 2017 19:30

@maicki Good question, I don't know which levels they use and how they react, only that they create a dispatch source of this kind to trigger eviction passes. We could find out!

garrettmoon commented 7 years ago

From @maicki on March 1, 2017 19:41

@Adlai-Holler I would definitely be in the game to find that out ;)

garrettmoon commented 7 years ago

Does this actually work better than the notification I wonder? I know the notification can sometimes come too late when lots of memory pressure occurs at once.

garrettmoon commented 7 years ago

From @maicki on March 16, 2017 15:38

@garrettmoon I just tested it out a bit. And it seems the notification from GCD arrives later than UIApplicationDidReceiveMemoryWarningNotification or -applicationDidReceiveMemoryWarning. That said it was just a quick couple of tests within the Simulator and on an iPod Touch and this could just be a hiccup as most of them are working on top of the notification system.

I looked into our code base and currently we "only" use it once in ASDK and once in PINCache, so don't know if this would benefit us in any case and just add some more custom code we have to handle.