2 Replies Latest reply on Aug 12, 2009 12:48 PM by Homestar9

    Performance hit from loading many variables on each request

    Homestar9 Level 1

      Hello fellow CFheads,

       

      My web application is customized for each of my clients based on a preferences file that gets called at the beginning of each page via Application.cfm.  The file is basically just a <cfscript> containing a list of variable names/values that sets various settings, values, and switches features on or off.

       

      For example:

       

      Sitename = “my web site”

      ActivateCalendar = “yes”

      ActivateOnlineStore = “no”

      Etc…

       

      Currently there are about 250 preferences variables that get loaded with each request and I’m wondering at what point I should be concerned with performance issues with loading so many variables (100? 500? 1000?).  Do you think this is something I should be concerned about or do you think loading a list of variables would take such a small performance hit that I shouldn’t be concerned at all?

       

      Curious to hear your thoughts and feedback.

       

        • 1. Re: Performance hit from loading many variables on each request
          TLC-IT Level 3

          Two suggestions here:

           

          1. Put all of these things into a single struct.  This makes it much easier to deal with.  Just as ColdFusion hands you a pre-defined structure named, say, FORM, you use the same technique to keep all of those perhaps-hundreds-of distinct values "in just one 'bag.' "  The implementation used in ColdFusion is directly comparable to the "hash" that is found under different buzzwords in different languages.  You need not fear a "performance hit," even with many thousands of keys:  the only reasonable vulnerability is "thrashing."
          2. Avoid placing massive amounts of data into things that might reside in RAM.  By "massive," I'm talking about, say, "more than a few dozen kilobytes," and of course it also depends on just how much simultaneous-user traffic your site might need to handle in real life.  For instance, if one of the items you're dealing with might be "an arbitrarily-sized document," you'll want to be storing that in a database, and keeping some kind of "handle" or "moniker" in your Application or Session data-pools, just in order to be able to find it again.

           

          While ColdFusion is somewhat of a structurally-weak language in this respect, I would consider placing the preferences-handling functionality in a single CFC which can be shared by all forms.  Should the implementation one day need to be changed, it is highly desirable to be able to do that in just one place.

          • 2. Re: Performance hit from loading many variables on each request
            Homestar9 Level 1

            Good suggestions.  I agree with you about putting everything into a structure. This also makes it easier when dumping variables in an exception error. Its pretty easy to purge the structure containing all of the site preferences and it will make any email sent by the exception error template that much smaller.