Rhino: speed optimization in omj/Interpreter.java
        Date:
             Tue, 26 Jun 2001 21:06:56 +0200
       From:
             Igor Bukanov <igor@icesoft.no>
 Organization:
             Wind River
         To:
             Norris Boyd <nboyd@atg.com>




Hi, Norris!

The attached Interpreter_patch contains a speed optimization patch that
tries to avoid creation of Double objects by keeping a parallel stack
for double values: instead of putting Double to the stack, DBL_MRK is
put and the real value is put to double stack (sDbl). Then when reading
stack with DBL_MRK, the double value from the double stack is used
wrapped to Double object when necessary. In addition local and vars
arrays are merged to stack array.

The attached before.txt and after.txt contain results of typical runs of
mozilla/js/benchmarks/all_bench.js before and after optimization on my
PC: Athlon 650/Red Hat 7.0/JDK 1.3.0 from Sun .

In number of cases the optimization actually slow down the executionby
5-10% (I guess due to the checks for DBL_MRK), but mostly it is a nice
sped up often by factor of 2 ot more with overall optimization win: 267
versus 218 seconds.

I guess it is possible to apply the same optimization to the optimizer
package, but in our browser we use strictly interpreter mode. Also by
changing signature of call/construct methods in Scriptable it is
possible to avoid creation of almost all objects currently allocated
during method calls, but that is for far future.

Regards, Igor
This commit is contained in:
nboyd%atg.com 2001-06-28 14:28:19 +00:00
Родитель 7f09885054
Коммит a3b59239d5
4 изменённых файлов: 601 добавлений и 214 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -57,7 +57,7 @@ class InterpreterData {
? INITIAL_STRINGTABLE_SIZE
: lastStringTableIndex * 2];
itsNumberTable = new Number[lastNumberTableIndex == 0
itsNumberTable = new double[lastNumberTableIndex == 0
? INITIAL_NUMBERTABLE_SIZE
: lastNumberTableIndex * 2];
@ -113,7 +113,7 @@ class InterpreterData {
String[] itsStringTable;
int itsStringTableIndex;
Number[] itsNumberTable;
double[] itsNumberTable;
int itsNumberTableIndex;
InterpretedFunction[] itsNestedFunctions;

Просмотреть файл

@ -432,6 +432,13 @@ public class ScriptRuntime {
return (index < args.length) ? toString(args[index]) : "undefined";
}
/**
* Optimized version of toString(Object) for numbers.
*/
public static String toString(double val) {
return numberToString(val, 10);
}
public static String numberToString(double d, int base) {
if (d != d)
return "NaN";

Просмотреть файл

@ -80,20 +80,29 @@ public class Main {
args = processOptions(cx, args);
int skip = 0;
if (fileList.size() == 0 && args.length > 0) {
skip = 1;
fileList.addElement(args[0]);
}
if (processStdin)
fileList.addElement(null);
// get the command line arguments after the name of the script,
// and define "arguments" array in the top-level object
Object[] array = args;
if (args.length > 0) {
int length = args.length - 1;
int length = args.length - skip;
array = new Object[length];
System.arraycopy(args, 1, array, 0, length);
System.arraycopy(args, skip, array, 0, length);
}
Scriptable argsObj = cx.newArray(global, array);
global.defineProperty("arguments", argsObj,
ScriptableObject.DONTENUM);
ScriptableObject.DONTENUM);
if (processStdin)
processSource(cx, args.length == 0 ? null : args[0]);
for (int i=0; i < fileList.size(); i++) {
processSource(cx, (String) fileList.get(i));
}
cx.exit();
return exitCode;
@ -107,9 +116,9 @@ public class Main {
for (int i=0; i < args.length; i++) {
String arg = args[i];
if (!arg.startsWith("-")) {
processStdin = false;
String[] result = new String[args.length - i];
for (int j=i; j < args.length; j++)
result[j-i] = args[j];
System.arraycopy(args, i, result, 0, args.length - i);
return result;
}
if (arg.equals("-version")) {
@ -146,9 +155,7 @@ public class Main {
processStdin = false;
if (++i == args.length)
usage(arg);
if (args[i].equals("-"))
processStdin = false;
processSource(cx, args[i]);
fileList.addElement(args[i].equals("-") ? null : args[i]);
continue;
}
usage(arg);
@ -369,4 +376,5 @@ public class Main {
static private final int EXITCODE_FILE_NOT_FOUND = 4;
//static private DebugShell debugShell;
static boolean processStdin = true;
static Vector fileList = new Vector(5);
}