4 ms·
Something surprising I learned recently is that this is an anti-pattern when building an iOS app. iOS has a memory compressor, so if you try to purge resources
by favorited 5y ago
Something surprising I learned recently is that this is an anti-pattern when building an iOS app. iOS has a memory compressor, so if you try to purge resources in a low-memory situation, it can cause memory use to spike as the things you're trying to free get decompressed.
The SDK provides a notification when memory pressure is high, so people try to get aggressive and purge their caches and unused assets when that notification arrives, but that only makes the problem worse.
- bombcar 5y agoSounds like they need a "free without uncompressing" feature.
- favorited 5y agoI think the issue would be that the compressor works on whole memory pages (I assume), so you'd need to know that the whole page could be freed. There might be kernel VM functions to handle that functionality manually, like if you were building a zone allocator or something?
- bombcar 5y agoI think it’s kind of related to how the oomkiller really needs to be integrated with the applications - the application needs to be able to identify memory as “critical, nice to have, ehhhhh, and cache” and then let the kernel throw them away as necessary. Once you start having to throw away critical pages you oomkill the process.
- kasabali 5y agoDoesn't good old uncompressed swap partition also have the same problem? Page is swapped out but it has to be paged in before the process owning it can evaluate what's where and release the junk?
- rogers18445 5y agoLinux and Android have that too. Called Zram. When using zstd a compression factor of 3.5 on swap memory is common.
- saagarjha 5y agoApple accelerates this compression in hardware, given that it's on an extremely hot path–especially when the system is under memory pressure.
- saagarjha 5y agoPlus, the code to handle that is likely little-used and may have been dumped. Just being able to run the handler that does low-memory handling may pull in things and increase pressure.
- deleted 5y ago[deleted]