I am using ScriptEngine in my app to evaluate some client code in my application. The problem is it's not performant enough and I need to take measures to improve the time of execution. Currently, it can take up to 1463ms (average is around 300ms) to eval an extremely simple script which is basically parameter replacement in URLs.
I'm looking for simple strategies to improve this performance without losing the scripting ability.
My first thought it to pool the ScriptEngine object and reuse it. I see in the spec it's meant to be reused but I haven't found any examples of anyone actually doing it.
Any ideas? Here is my code:
ScriptEngineManager factory = new ScriptEngineManager();
GroovyScriptEngineImpl engine = (GroovyScriptEngineImpl)factory.getEngineByName("groovy");
engine.put("state", state;
engine.put("zipcode", zip);
engine.put("url", locationAwareAd.getLocationData().getGeneratedUrl());
url = (String) engine.eval(urlGeneratorScript);
Any feedback would be appreciated!