зеркало из https://github.com/mozilla/pjs.git
Subject:
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:
Родитель
7f09885054
Коммит
a3b59239d5
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -57,7 +57,7 @@ class InterpreterData {
|
||||||
? INITIAL_STRINGTABLE_SIZE
|
? INITIAL_STRINGTABLE_SIZE
|
||||||
: lastStringTableIndex * 2];
|
: lastStringTableIndex * 2];
|
||||||
|
|
||||||
itsNumberTable = new Number[lastNumberTableIndex == 0
|
itsNumberTable = new double[lastNumberTableIndex == 0
|
||||||
? INITIAL_NUMBERTABLE_SIZE
|
? INITIAL_NUMBERTABLE_SIZE
|
||||||
: lastNumberTableIndex * 2];
|
: lastNumberTableIndex * 2];
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class InterpreterData {
|
||||||
String[] itsStringTable;
|
String[] itsStringTable;
|
||||||
int itsStringTableIndex;
|
int itsStringTableIndex;
|
||||||
|
|
||||||
Number[] itsNumberTable;
|
double[] itsNumberTable;
|
||||||
int itsNumberTableIndex;
|
int itsNumberTableIndex;
|
||||||
|
|
||||||
InterpretedFunction[] itsNestedFunctions;
|
InterpretedFunction[] itsNestedFunctions;
|
||||||
|
|
|
@ -432,6 +432,13 @@ public class ScriptRuntime {
|
||||||
return (index < args.length) ? toString(args[index]) : "undefined";
|
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) {
|
public static String numberToString(double d, int base) {
|
||||||
if (d != d)
|
if (d != d)
|
||||||
return "NaN";
|
return "NaN";
|
||||||
|
|
|
@ -80,20 +80,29 @@ public class Main {
|
||||||
|
|
||||||
args = processOptions(cx, args);
|
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,
|
// get the command line arguments after the name of the script,
|
||||||
// and define "arguments" array in the top-level object
|
// and define "arguments" array in the top-level object
|
||||||
Object[] array = args;
|
Object[] array = args;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
int length = args.length - 1;
|
int length = args.length - skip;
|
||||||
array = new Object[length];
|
array = new Object[length];
|
||||||
System.arraycopy(args, 1, array, 0, length);
|
System.arraycopy(args, skip, array, 0, length);
|
||||||
}
|
}
|
||||||
Scriptable argsObj = cx.newArray(global, array);
|
Scriptable argsObj = cx.newArray(global, array);
|
||||||
global.defineProperty("arguments", argsObj,
|
global.defineProperty("arguments", argsObj,
|
||||||
ScriptableObject.DONTENUM);
|
ScriptableObject.DONTENUM);
|
||||||
|
|
||||||
if (processStdin)
|
for (int i=0; i < fileList.size(); i++) {
|
||||||
processSource(cx, args.length == 0 ? null : args[0]);
|
processSource(cx, (String) fileList.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
cx.exit();
|
cx.exit();
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -107,9 +116,9 @@ public class Main {
|
||||||
for (int i=0; i < args.length; i++) {
|
for (int i=0; i < args.length; i++) {
|
||||||
String arg = args[i];
|
String arg = args[i];
|
||||||
if (!arg.startsWith("-")) {
|
if (!arg.startsWith("-")) {
|
||||||
|
processStdin = false;
|
||||||
String[] result = new String[args.length - i];
|
String[] result = new String[args.length - i];
|
||||||
for (int j=i; j < args.length; j++)
|
System.arraycopy(args, i, result, 0, args.length - i);
|
||||||
result[j-i] = args[j];
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (arg.equals("-version")) {
|
if (arg.equals("-version")) {
|
||||||
|
@ -146,9 +155,7 @@ public class Main {
|
||||||
processStdin = false;
|
processStdin = false;
|
||||||
if (++i == args.length)
|
if (++i == args.length)
|
||||||
usage(arg);
|
usage(arg);
|
||||||
if (args[i].equals("-"))
|
fileList.addElement(args[i].equals("-") ? null : args[i]);
|
||||||
processStdin = false;
|
|
||||||
processSource(cx, args[i]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
usage(arg);
|
usage(arg);
|
||||||
|
@ -369,4 +376,5 @@ public class Main {
|
||||||
static private final int EXITCODE_FILE_NOT_FOUND = 4;
|
static private final int EXITCODE_FILE_NOT_FOUND = 4;
|
||||||
//static private DebugShell debugShell;
|
//static private DebugShell debugShell;
|
||||||
static boolean processStdin = true;
|
static boolean processStdin = true;
|
||||||
|
static Vector fileList = new Vector(5);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче