04/08/2004: Optimization for JudoScript: JudoUtil.registerToBSF is an expensive method to call.
It seems to me that a scripting engine only needs to register with the BSF engine once. I think that JudoScript registers with the engine every time a script is invoked. In order to avoid this situation, I added a static variable to track the bsfStatus. In the test case that I was executed, I was able to reduce calls to Class.forName() from 8,061 to 43 and the created objects from 649,620 to 162. This also saved 2.6% of execution time.
public static String bsfStatus = "UNKNOWN"; public static void registerToBSF() { if (bsfStatus.equals("UNKNOWN")) { try { Class[] params = new Class[] {String.class, String.class, Class.forName("[Ljava.lang.String;")}; Method m = Class.forName("com.ibm.bsf.BSFManager").getMethod("registerScriptingEngine", params); Object[] vals = new Object[] {"judoscript", "com.judoscript.BSFJudoEngine", new String[] {"judo", "jud"}}; m.invoke(null, vals); bsfStatus = "AVAILABLE"; } catch (Exception e) { bsfStatus = "UNAVAILABLE"; } // if BSF is not there, so be it. } }
04/05/2004: Jprobe Analysis Reduces Execution Time by 5%
Using JProbe, I noticed that my application was repeatedly compiling the same JudoScript scripts. I added a cache for compiled JudoScript scripts which reduced the calls to ParserHelper.parse():
Run | Calls | Cumulative Time | Cumulative Objects Percent | Cumulative Objects |
---|---|---|---|---|
1 | 1,300 | 5.5% | 13.6% | 1,116,603 |
2 | 13 | 0.3% | 0.3% | 23,456 |
Not a bad first optimization for our first use of the JProbe profiler.