Please note, new blog at http://www.acheron.org/darryl/

Singletons dramatically improve performance

I've just spent the last couple of days working on improving the speed of an application. One of the biggest bottlenecks we discovered was the continuous creation of objects (business logic) that do not hold their own instance data. We solved the problem by creating them all as singletons! A singleton is an object that is only created once - only one instance of it exists in memory. In ColdFusion, you essentially achieve this in ColdFusion by checking to see if an object already exists in a particular scope, and if it does, then use it, otherwise, create it. We created a core method to create singletons, and placed our singletons in application or session scope, with the key being the full component path (e.g. applicatiom["com.foo.bar.componentName"]). I think a lot can be learned from J2EE patterns.

By Anonymous Christopher Town, at 3/20/2005 04:14:00 pm  

The mach-ii framework (www.mach-ii.com) for CFMX takes advantage of the singleton pattern; thereby dramatically increasing performance for any application. In a typical mach-ii application, you often have 80-100% of your business logic residing within a large singleton under the application scope.

It's great to see that object oriented design patters, having been tried and tested for many years, are now obtainable with CFML.



» Post a Comment

Trackbacks:

» Create a Link