Mesa 23.1 Lands Improvement For Better Handling Steam’s Shader Cache


An optimization to Mesa’s shader database cache eviction handling has been merged to Mesa 23.1 with a focus on benefiting Steam’s shader pre-caching.

Dmitry Osipenko of Collabora has seen his month-old merge request finally land to optimize the Mesa shader database cache eviction process. Osipenko explained in the MR:

Whenever mesa-db cache hits size limit, a half of cache is evicted. It works fine in general, but some use-cases are suffering from the large cache evictions. In particular a Steam shader pre-caching can easily fill up Mesa shader cache and in this case it’s much more preferred to keep more entries in cache rather than remove half of the cache.

To mitigate large cache evictions, we will split mesa-db cache into multiple smaller parts such that only one part will be evicted at a time. In average this MR reduces cache eviction time by x40 and significantly improves cache hit rate after reaching the cache size limit.

This feature adds the MESA_DISK_CACHE_DATABASE_NUM_PARTS and MESA_DISK_CACHE_DATABASE_EVICTION_SCORE_2X_PERIOD environment variables for better controlling the mesa-db cache handling. With making use of the new feature for next quarter’s Mesa 23.1 release, «This patch brings x40 performance improvement of cache eviction time using multipart cache vs a single file cache due to a smaller eviction portions and more optimized eviction algorithm.«