Monday 16 September 2013

How sausages are made

Today I pulled back the curtain on some of ColdFusion's inner workings... and hastily closed the curtain and declared "nothing to see here. Move along".

For reasons I won't go into, I found myself needing to decompile some of my CFML code today, to try to work out WTF was going on under the hood. It was interesting reading and it solved my issue, but I noticed something else which I then looked at more closely. With a (small) measure of horror.

Here's my code:

<cfset a = [1,2,3,4,5]>

And here's how ColdFusion translates that to Java:

_arraySetAt(this.___IMPLICITARRYSTRUCTVAR0, new Object[] { "1" }, "1");
_arraySetAt(this.___IMPLICITARRYSTRUCTVAR0, new Object[] { "2" }, "2");
_arraySetAt(this.___IMPLICITARRYSTRUCTVAR0, new Object[] { "3" }, "3");
_arraySetAt(this.___IMPLICITARRYSTRUCTVAR0, new Object[] { "4" }, "4");
_arraySetAt(this.___IMPLICITARRYSTRUCTVAR0, new Object[] { "5" }, "5");

Blimey. What a lot of rigamarole to create an array.

In contrast, Railo does this:
        new Object[] { ConstantsDouble._1, ConstantsDouble._2, ConstantsDouble._3, ConstantsDouble._4, ConstantsDouble._5 }

The Railo version seems more in-keeping with what I expect.

I can't help but think the two approaches here are demonstrative of why Railo is so much faster than ColdFusion.

I seriously cannot understand why it is CF is making an array out of each element of the array it's creating. Weird.

Anyway... that was all. It was just a bit interesting.