ColdFusion 9 optimization
ColdFusion 9 has giant bottlenecks, we made it more than 100% faster with the following fixes. In other words, for some requests, instead of taking 5 seconds, they takes 2 seconds.
That's the kind of improvement ColdFusion get by having a real developer around 😉
package com.onassignment.optimization;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import coldfusion.compiler.NeoTranslator;
import coldfusion.vfs.VFSFileFactory;
import coldfusion.runtime.CfJspPage;
import com.onassignment.hibernate.Initializer;
import com.onassignment.Configuration;
public aspect ColdFusion {
private static Configuration configuration = (Configuration)Initializer.getApplicationContext().getBean("Configuration");
/////////// First fix
private static ConcurrentMap<String,Timestamps> pathToTimestamp = new ConcurrentHashMap<String,Timestamps>();
private static long FIVE_SECOND_IN_MILLI = 5000;
pointcut getLastModifiedTime(String canonicalPagePath):
execution(public long NeoTranslator.getLastModifiedTime(..)) && args( canonicalPagePath );
long around(String canonicalPagePath): getLastModifiedTime( canonicalPagePath) {
Long current = System.currentTimeMillis();
Timestamps timestamps = pathToTimestamp.get(canonicalPagePath);
if ( ( timestamps == null ) ||
( !configuration.isEnableLastModifiedTimeOptimization() ) ||
( (timestamps.lastLookup + FIVE_SECOND_IN_MILLI) < current )
){
long currentFileTime = proceed(canonicalPagePath);
timestamps = new Timestamps(current,currentFileTime);
pathToTimestamp.put(canonicalPagePath, timestamps);
return currentFileTime;
} else {
return timestamps.fileModifiedTime;
}
}
//////////// Second fix
static ConcurrentMap<String,Boolean> urlToBoolean = new ConcurrentHashMap<String,Boolean>();
pointcut checkIfVFile(String url):
execution(public static boolean VFSFileFactory.checkIfVFile(..)) && args( url );
boolean around(String url): checkIfVFile( url) {
if (url == null){
return false;
}
Boolean isIt = urlToBoolean.get(url);
if (isIt != null){
return isIt;
}
isIt = proceed( url );
urlToBoolean.put( url, isIt );
return isIt;
}
//////////// Third fix
public String CfJspPage.pagePath;
pointcut getPagePath(CfJspPage called):
execution(public String getPagePath(..)) && target(called);
String around(CfJspPage called): getPagePath( called) {
if (called.pagePath == null ){
called.pagePath = proceed(called);
}
return called.pagePath;
}
}
