YAFLogo

Posted by: thethanghn - Friday, 29 October 2010 03:31:49
Hi, As I look into YAF.Classes.Config class, I found that each of Property will search through the AppSettings collection and get the value from it. I think there is 2 points would be slow: - Unnecessary look up - Retrieve value from config file again and again Whether it'd better if we cache them in separate static variable? Sincerely Thangnt

Posted by: thethanghn - Friday, 29 October 2010 06:48:55
Some of refactored code: [code] public static string BoardID { get { if (string.IsNullOrEmpty(boardID)) boardID = GetConfigValueAsString("YAF.BoardID") ?? "1"; return boardID; } } public static bool DisableJQuery { get { if (!disableJQuery.HasValue) disableJQuery = GetConfigValueAsBool("YAF.DisableJQuery", false); return disableJQuery.Value; } } [/code]

Posted by: Jaben - Friday, 29 October 2010 07:24:32
I've done extensive performance profiling of the YAF project. This has never come up as a place that needed refactoring for performance reasons. There is always "better" code... but instead of your solution I'd offer a complete abstraction of the configuration system that provided a caching system.