Umbraco Dictionary Key Performance
I've recently had the task of optimizing a clients website. On my tour of the site i noticed an instance where 20-30 dictionary keys are requested in succession for a single view.
I decided to do some performance testing and find out how quickly the action is performed before and after caching.
I made 25 keys in the backoffice with naming following this scheme "key0", "key1" and so on.
controller action:
public string Get() { StringBuilder sb = new StringBuilder(); var timer = new Stopwatch(); timer.Start(); for (var x = 0; x < 25; x++) Umbraco.GetDictionaryValue("key" + x); timer.Stop(); return timer.ElapsedMilliseconds + "ms " + timer.ElapsedTicks + " ticks"; }
Results were on first run (presumably includes a database query)
112ms 262011 ticks
then progressively lower
32ms 74887 ticks
4ms 10292 ticks
1ms 3733 ticks
112ms 262011 ticks
then progressively lower
32ms 74887 ticks
4ms 10292 ticks
1ms 3733 ticks
It's progressively lower because of SQL Server cache the results I think and the GetDictionanary method still not be cached.. I'm thinking how to cache the dictionary myself too.
ReplyDeleteThis was great to read, thank you.
ReplyDelete