function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ssoftwaressoftware 

Performance benefits of storing custom setting in a map

Hi All,

My application frequently utilises a list custom setting in a for loop.
Custom_Setting__c cs = Custom_Setting__c.getInstance(key);

Is there any additional benefit to store all the values in a Map before the for loop begins and then access the Map in the loop?
Map<String, Custom_Setting__c> mapCS = Custom_Setting__c.getAll();
for (....) {
Custom_Setting__c cs = mapCS.get(key);
}

My guess is that as custom settings are already utlizing application cache, there is probably no added benefit. But I would like to double check if this is correct as I want to optimise the for loop as much as possible.
 
Best Answer chosen by ssoftware
bob_buzzardbob_buzzard
I did some analysis on this recently and couldn't find any benefit to storing custom settings in variables unless you are retrieving the same one several hundred thousand times, and even then it was minimal.