Internal Caches
Overview
Prysm has various internal caches that control how CPU and GPU memory is reused. The caches are there to avoid expensive allocations - of CPU and GPU memory - every frame. This improves performance at the cost of higher memory usage. The default cache sizes are set to reasonable defaults but depending on the given UI, the sizes might not be optimal. There are situations where user code might have to adjust the caches:
- If a given UI scene normally uses less memory than the default cache sizes, then memory is probably retained in the caches while not being actively used. In this situation, it might be worth considering lowering the cache sizes.
- If a given UI scene normally uses more memory than the default cache sizes, the caches will be pruned every frame only to allocate memory again in the next frame. In this case, it makes sense to increase the cache size.
The setting of cache sizes is done with the cohtml::View::QueueSetCacheCountSize
and cohtml::View::QueueSetCacheBytesSize
APIs. The current cache sizes can be inspected with cohtml::View::GetCacheBytesStats
and cohtml::View::GetCacheCountStats
. The caches can also be force cleared at any given time with cohtml::View::QueueClearCaches
.
Caches
The types of internal caches are given by the cohtml::InternalCaches
enumeration. The APIs for the cache control operate on different cache depending on the provided cache
argument.
cohtml::View* view;
...
// set the cache size for the Scratch Layer Textures
view->QueueSetCacheBytesSize(cohtml::ICACHE_ScratchLayers, 24 * 1024 * 1024); // 24MB
// set the cache size for the Depth-Stencil Textures
view->QueueSetCacheBytesSize(cohtml::ICACHE_DepthStencilTextures, 20 * 1024 * 1024); // 20MB
Here is an overview with the types of caches that Prysm has:
ICACHE_Shadows
- GPU textures used for shadow shapes created due tobox-shadow
andtext-shadow
ICACHE_Paths
- cache for CPU objects for complex path shapesICACHE_Textures
- cache for GPU textures used for client images used in<img>
elements orbackground-image
ICACHE_ScratchLayers
- GPU textures used for composing layers with different effects. Prysm has to create layers for certain CSS effects (opactiy
,filter
,backdrop-filter
,mix-blend-mode
,mask-image
, etc.). Multiple layers are packed on a single scratch layer texture.ICACHE_ScratchTextures
- GPU textures used for intermediate render targets when Prysm renders certain effects like blur, drop shadow, or color mixing due tomix-blend-mode
ICACHE_GfxCommandBuffers
- cache for CPU objects used for recording paint commands for the Prysm’s rendering libraryICACHE_GfxCommandProcessors
- cache for CPU objects used for processing paint commands and generating backend commands for the rendering backendICACHE_SVGSurfaces
- GPU textures used for caching and reusing already painted SVGsICACHE_BackdropFilterSurfaces
- GPU textures used as intermediate textures when rendering backdrop filter effectsICACHE_DepthStencilTextures
- GPU depth stencil textures used in various places when executing clipping operations or rendering path objects.
For more information on how to monitor and diagnose the state of some of the GPU caches, check out the “Precise Scratch Texture Manager monitoring” section on the Inspector Features page.