I haven't blogged in awhile due to schedule, but had to blog this experience I recently had while attempting to stabilize an application and enhance performance.
I have always taken for granted that createObject was lightning fast... Well, as fast as feasibly possibly under a given JVM.
I think I was dead wrong and this may be an issue for Adobe to address. I am unclear on the internals of course. But I have been up against OOMs on my current project and wanted to test out using soft reference (cached objects) and use duplicate from the cache rather than createObject.
Far stretch I know... but hey it was worth a try. What was revealed was that performance was negligible and createObject was faster in some intervals. Memory behaved the same, no real bonus. So in discussion with a fellow consultant I told him I'd ship a zip to him for test purposes as he had said he'd seen a significant performance enhancement with duplicate (not true by the way).
What happened next totally shocked me. To simplify the test code I snagged my VO.cfc out of it's proper place (several dirs down i.e. sitedir, com, bus, app, model, vo.. you get the idea) and put it in the root of the calling cfm. I then removed all the pathing (dot notation) from my createObject call and executed the cfm to see if it would run ok after the change.
The test was a loop of 10k over this create object call. I was seeing execution times of around 30 seconds. When I ran the updated code it went to 577 milliseconds... I am still befuddled by this. Is there that much overhead with pathing?
I initially thought it was a mapping issue because I had been using mappings, but absolute path from root was just as slow.
Please Adobe tell me this is Sun's jvm and not your code. I know this is negligible with 100 or so creates, but imagine the boost if I did find something here.
For clarification I am running on a Mac (OS X, CF running in JBOSS), but also tested on my old Dell (XP, CF running in JRUN). I didn't see as dramatic a difference on WIntel, but my exec time went from 30 seconds to 4 seconds. I am happy with 10x faster on Windows too...
Any insight here is greatly appreciated.
Example Code:
<cfscript>
currentTime = now();
rqaArray = arrayNew(1);
initTime = getTickCount();
for (index=1; index lte 10000; index = index + 1)
{
// pathing example replace vo reference with
//this pathing call com.mercer.mercerOnline.model.RQASummaryVO
rqa = createObject("component","RQASummaryVO");
rqa.rqaID = index;
rqa.type = "theType";
rqa.createDate = currentTime;
rqa.submitDate = currentTime;
rqa.client = "currentClient";
rqa.clientID = "clientID";
rqa.status = 6;
rqa.userID = 123456;
rqa.agencyID = "agencyID";
rqa.predecessorID = 0;
rqa.locked = false;
rqa.deleted = false;
rqa.title = "The Title "index#;
rqa.policyNumber = "thePolicyNum";
rqa.agencyName = "agencyName";
rqa.totalPremium = "totalPremium";
rqa.hasMessages = false;
rqa.isAssigned = false;
rqa.assignedTo = "";
rqa.proposedEffDate = currentTime;
rqa.proposedExpDate = currentTime;
rqa.agentName = "agentName";
ArrayAppend(rqaArray,rqa);
}
endTime = getTickCount();
totalTime = endTime - initTime;
</cfscript>
<cfdump var="#arrayLen(rqaArray)#">
<cfdump var="#rqaArray[10000]#" />
<cfdump var="#totalTime#" />