Local variables are assigned to JVM registers, while external variables are accessed by a method call. The following code illustrates a use of local variables to improve the performance.
function test(){ Object = Object // this line makes it faster for(i = 0; i < 1000; i++){ Object() } }
eval() is a relatively heavy operation. So eval() call in a loop should be expanded if it might be a perfomance bottle neck.
This can be rewritten as follows.
for(i = 0; i < 1000; i++){ eval("x" + i + " = " + i) }
ca = openCharArray() for(i = 0; i < 1000; i++){ ca.write("x" + i + " = " + i + "\n") } eval(ca.toString())
pnuts.lang.PnutsImpl class defines an interface of script interpreter's implementation. The following classes are implementation classes of the interface provided in the Pnuts distribution.
- pnuts.lang.PnutsImpl
- Pure interpreter
- pnuts.compiler.CompilerPnutsImpl
- On-the-fly Compiler
- pnuts.ext.CachedPnutsImpl
- Mixed mode, which caches compiled (or parsed) scripts and reuse them
On-the-fly compiler usually runs faster than pure interpreter. It is appropriate for interactive use, since the compilation overhead does not matter.
If Pnuts is embedded in an application as a scripting engine and same scripts are executed over and over, mixed mode is the right choice. Since on-the-fly compilation takes a few milliseconds to a few hundreds milliseconds depending on the size of scripts, caching the compiled code would improve the performance.
If the application uses a limited set of scripts, the combination of pure interpreter and precompiled scripts is efficient because there is no compilation overhead and the bytecode compiler package in Pnuts can be removed if needed.
You might consider to use makeProxy() function.