CIContext memoryLimit tips?

I would like to use the memory limit during interactive editing on iOS to decrease jetsam risk. However, I'm unsure of what to set it to. Do you have a recommendation as a fraction of physical memory?

I have set the extended virtual memory entitlement, but I don't know what fraction of physical memory (or more) that entitlement enables - perhaps I should use a larger memory limit for M1-based iPads?

Answered by Engineer in 893536022

The entitlement will only increase the virtual address space of the app, which in turn allows CIContext to retain more intermediate renders. This improves the chances of reusing them during interactive renders. Since CIContext intermediates are cached as volatile memory, this entitlement does not impact the risk of jetsam.

The entitlement will only increase the virtual address space of the app, which in turn allows CIContext to retain more intermediate renders. This improves the chances of reusing them during interactive renders. Since CIContext intermediates are cached as volatile memory, this entitlement does not impact the risk of jetsam.

Still a bit confused. If the intermediates are volatile, then I would think that they wouldn't matter for the memoryLimit budget, right? So the memoryLimit is for things other than intermediates? If so, what fraction of real memory do you advise on iOS?

We anticipate that the default memory limit for CIContext (256MB) will be a relatively small fraction of the app’s jetsam limits on currently supported iOS/iPadOS devices. In fact, this option was introduced to increase the limit for more powerful devices, such as the iPad Pro.

I am not aware of any applications that utilize a lower limit for interactive rendering, so I cannot accurately predict the performance impact.

Intermediates transition between non-volatile and volatile states as they are connected to pending and completed GPU tasks.

CIContext memory limits (or static let memoryTarget: CIContextOption) determine the amount of non-volatile memory, which will contribute to the jetsam pressure, that CIContext will use to complete a renderTask.

Ok, that helps. It sounds like the idea is that we consider increasing the limit to get better performance, rather than decrease it because it's already low. Do you have a percentage you recommend vs. physical memory?

I don’t have a definitive answer for that on iOS, primarily because I’m not sure how the jetsam limit scales with the physical memory of the device. Additionally, the memoryTarget only limits CoreImage allocations, but there will be additional memory required for decoding RAW (or JPG/HEIC) images, as well as other allocations and buffers used by the app that would need to be measured.

I believe that os_proc_available_memory could serve as a guide.

I suggest experimenting with 512 or 1024MB as I think there should be enough budget for the other allocations, and there’s a good chance that further increases would provide diminishing returns (especially considering the target screen size).

CIContext memoryLimit tips?
 
 
Q