My Projects
Search Blog

Categories
Archives
Photo Albums
RSS

Powered by
BlogCFM v1.15

24 August 2006
Debugging ajaxCFC
Rey Bango posted this to cf-talk,and I thouht wothy of blogging.

Here's a tip that I wanted to share within everyone here. It may be
known but I only found out about it today and wanted to share.
If you ever get the dreaded "Invalid Reply from Server" message from
AjaxCFC, spark up Firefox/FireBug and call your site from your local IP.
This will give you the actual message that DWR is sending back.

Put a stop point at about line 517 (or immediately after
"batch.req.send(query);") of engine.js and look for the "batch" object.
In the there you'll find the "req" (XMLHttpRequest request) object which
has a standard attribute called responseText. That will give you all of
the details of your error but for security reasons, it only shows it via
your local IP address (127.0.0.1).

Rey...
Posted by rickroot at 5:53 PM | Link | 2 comments
18 August 2006
CFML String Concatenation is SLOW! Use Java StringBuffer instead

I was trying to speed up a process of mine that involves a large amount of string concatenation.

In other words, <cfset str = str & someOtherString>

Turns out there's a much faster way.  In my case, I was dynamically generating an data file from a query.  Each row had let's say 50 fields.  Generation of each row required 3 string concatenations at a time (maybe more, depending on how it worked when compiled to the servlet).  Do a drop of 5000 records, and well, that's a lot of string concats!  750,000 at a minimum.

Someone on cf-talk suggested using a StringBuffer might be wise because Coldfusion probably creates a new string object every time you do <cfset foo = foo & foo2>.  So I decided to write some code to test it out.

Sure enough, using the java StringBuffer class is quite a lot faster.  On my local machine, I ran the following code (see below).  The CFML method completed in 89 seconds, while the java StringBuffer method completed in only 28 seconds - about 1/3 of the time!

Here's the code, if you're interested:

<cfset a = "">
<cfset starttime = now()>
<cfset cnt = 0>
<cfloop index="i" from="1" to="2000000">
    <cfset a = a & "This is some crazy stuff. ">
    <cfset cnt = cnt + 26>
    <cfif i mod 1000 is 0>
        <!--- write to file and reset string to empty --->
        <cfset a = "">
    </cfif>
</cfloop>
<cfoutput><p>Done with #cnt# bytes in #abs(dateDiff('s',Now(),starttime))# seconds.</p></cfoutput>

<cfset a = createObject("java","java.lang.StringBuffer")>
<cfset starttime = now()>
<cfset cnt = 0>
<cfloop index="i" from="1" to="2000000">
    <cfset a.append("This is some crazy stuff. ")>
    <cfset cnt = cnt + 26>
    <cfif i mod 10000 is 0>
        <!--- write to file and reset string to empty --->
        <cfset a = createObject("java","java.lang.StringBuffer")>
    </cfif>
</cfloop>
<cfoutput><p>Done with #cnt# bytes in #abs(dateDiff('s',Now(),starttime))# seconds.</p></cfoutput>

 

 

Posted by rickroot at 7:38 AM | Link | 5 comments