SQL Tips

This is a handy tip courtesy of Matt Woodward

you actually pay a penalty by not referring to the port directly in your connection strings.

For optimal connection performance, you should set the portNumber when you connect to a named instance. This will avoid a round trip to the server to determine the port number. If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.

Another tip from the Communications at A.C.M. magazine (06/2011 Vol. 54 No. 6) – 10 Rules for Scalable Performance in ‘Simple Operation’ Datastores (Pg 78) –

For security reasons, RDBMSs insist onthe application being run in a separate address space, using ODBC or JDBC for DBMS interaction. The overhead of these communication protocols is high; running a SQL transaction requires several back-and-forth messages over TCP/IP. Consequently, any programmer seriously interested in performance runs transactions using a stored-procedure interface, rather than SQL commands over ODBC/ JDBC. In the case of stored procedures, a transaction is a single over-and-back message. The DBMS further reduces communication overhead by batching multiple transactions in one call.

Popularity: 3% [?]

Optimizing session handling sites for Bots

If your site handles sessions and undergoes PCI compliance testing or is frequently indexed by Search Engine bots, a really quick optimization is to limit the session limit based on the User Agent.

In ColdFusion, you can do something like:
if (REFindNoCase('Slurp|Googlebot|BecomeBot|bingbot|Mediapartners-Google|ZyBorg|RufusBot|EMonitor', cgi.http_user_agent)) {
this.SessionTimeout = CreateTimeSpan(0, 0, 0, 10);
this.SessionTimeout = CreateTimeSpan(0, 1, 0, 0);

which obviously limits the session length to 10 seconds for bots and 1 hour for normal site visitors. This prevents server memory from needlessly being consumed by each of the bot sessions (assuming they dont store cookies).

PS. If the bots are capable of handling cookies, this could create issues since the session wont be maintained for more than 10 seconds – so be sure to test before making changes. For additional clarification, since you are not being deceptive and presenting different content to users vs. bots, you won’t be penalized for this.

Popularity: 5% [?]

Coldfusion Infinite Loop Error

If you ever run into the error:
and it repeats a hundred times, make sure you dont have an infinite loop in your code.

Just found this the hard way and didn’t find any specific references on Google for it.

Popularity: 12% [?]

Interesting Javascript Tips

Despite being a Javascript user for years, there were some things I still didn’t know.
Here are some of the interesting points I found from Ben Cherry’s presentation

names are always hoisted to the top of their scope
and always initialized to undefined

var foo = 1;
(function () {
alert(foo); // undefined
var foo = 2;
alert(foo); // 1

var foo = 1;
(function () {
alert(foo); // alerts "1"
// in the previous example foo is hoisted to the top as "undefined"
alert(foo); // 1

CSS expressions are evaluated right-to-left!

#foo div a {/* ... */}

this starts by looking at every
then it looks for those whose parent is

then it checks to see if its parent is #foo

parseInt needs radix!

parseInt("123"); // 123
parseInt("10"); // 10
parseInt("010"); // 8 -> WTF?

// with a radix
parseInt("010", 10); // 10 -> crisis averted!

never forget your radix

avoid inline scripts
these cannot be cached or minified
only put dynamic values here

you can detach sub-trees

var elem = $("#myelem"),
parent = elem.parent();

// ... muck with elem and sub-elements ...

.detach() is new in jQuery 1.4

how to make BC.util?

BC.util = (function (BC) {
var util = {},
foo; // private variable

// public
util.someFunction = function () {};

// private
function someOther() {}

return util;


// slow method
var i;
for (i = 0; i < someArray.length; i += 1) {
// ...
// faster
var i, l;
for (i = 0, l = someArray.length; i < l; i += 1) {
// ...

Popularity: 4% [?]