Skip to content

Commit

Permalink
perf(BaseGrammar): Avoid isInstanceOf in wrapColumn
Browse files Browse the repository at this point in the history
`isInstanceOf` takes about 30-40 ms per column.  For just one table with
6 columns, this is close to a quarter of a second.  This adds up.

Instead, just checking if the variable is an object that has a `getSQL`
key (which we assume is a method), we save all of that time.
  • Loading branch information
elpete committed Feb 20, 2018
1 parent 4c4f0d5 commit 15042ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion models/Grammars/BaseGrammar.cfc
Expand Up @@ -700,7 +700,11 @@ component displayname="Grammar" accessors="true" {
* @return string
*/
public string function wrapColumn( required any column ) {
if ( isInstanceOf( column, "qb.models.Query.Expression" ) ) {
// In this case, isInstanceOf takes ~30 ms while this takes ~0 ms
if ( ! isSimpleValue( column ) &&
isObject( column ) &&
structKeyExists( column, "getSQL" )
) {
return column.getSQL();
}

Expand Down

0 comments on commit 15042ce

Please sign in to comment.