removed some old stuff, added profiler, minor performance tuning

This commit is contained in:
Arndt 2016-08-20 18:53:50 +02:00
parent 42e9ddbdd1
commit f70dd3c3ac
22 changed files with 234 additions and 802 deletions

View file

@ -25,8 +25,6 @@ final class BExpression
private static final int NUMBER_EXP = 33;
private static final int VARIABLE_EXP = 34;
private static final int DUMPPOS_EXP = 40;
private int typ;
private BExpression op1;
private BExpression op2;
@ -147,10 +145,6 @@ final class BExpression
{
exp.typ = NOT_EXP;
}
else if ( "dumppos".equals( operator ) )
{
exp.typ = DUMPPOS_EXP;
}
else
{
nops = 0; // check elemantary expressions
@ -263,7 +257,6 @@ final class BExpression
case NUMBER_EXP: return numberValue;
case VARIABLE_EXP: return ctx.getVariableValue( variableIdx );
case NOT_EXP: return op1.evaluate(ctx) == 0.f ? 1.f : 0.f;
case DUMPPOS_EXP: ctx.expressionWarning( "INFO" ); return op1.evaluate(ctx);
default: throw new IllegalArgumentException( "unknown op-code: " + typ );
}
}

View file

@ -31,8 +31,6 @@ public abstract class BExpressionContext
private BufferedReader _br = null;
private boolean _readerDone = false;
private BExpressionReceiver _receiver;
private Map<String,Integer> lookupNumbers = new HashMap<String,Integer>();
private ArrayList<BExpressionLookupValue[]> lookupValues = new ArrayList<BExpressionLookupValue[]>();
private ArrayList<String> lookupNames = new ArrayList<String>();
@ -58,20 +56,21 @@ public abstract class BExpressionContext
private byte[] currentByteArray = null;
private boolean currentInverseDirection= false;
public List<BExpression> expressionList;
private List<BExpression> expressionList;
private int minWriteIdx;
// build-in variable indexes for fast access
private int[] buildInVariableIdx;
protected float[][] arrayBuildInVariablesCache;
private float[][] arrayBuildInVariablesCache;
private float[] hashBucketVars;
abstract String[] getBuildInVariableNames();
protected float getBuildInVariable( int idx )
protected final float getBuildInVariable( int idx )
{
return arrayBuildInVariablesCache[idx][currentHashBucket];
return hashBucketVars[idx];
}
private int linenr;
@ -105,10 +104,10 @@ public abstract class BExpressionContext
// create the build-in variables cache
int nBuildInVars = getBuildInVariableNames().length;
arrayBuildInVariablesCache = new float[nBuildInVars][];
for( int vi=0; vi<nBuildInVars; vi++ )
arrayBuildInVariablesCache = new float[hashSize][];
for( int hi=0; hi<hashSize; hi++ )
{
arrayBuildInVariablesCache[vi] = new float[hashSize];
arrayBuildInVariablesCache[hi] = new float[nBuildInVars];
}
}
@ -264,9 +263,10 @@ public abstract class BExpressionContext
public void evaluate( int[] lookupData2 )
{
lookupData = lookupData2;
for( BExpression exp: expressionList)
int n = expressionList.size();
for( int expidx = 0; expidx < n; expidx++ )
{
exp.evaluate( this );
expressionList.get( expidx ).evaluate( this );
}
}
@ -279,7 +279,7 @@ public abstract class BExpressionContext
*
* @return true if the data is equivilant to the last calls data
*/
public boolean evaluate( boolean inverseDirection, byte[] ab, BExpressionReceiver receiver )
public boolean evaluate( boolean inverseDirection, byte[] ab )
{
requests ++;
lookupDataValid = false; // this is an assertion for a nasty pifall
@ -291,6 +291,7 @@ public abstract class BExpressionContext
int crc = Crc32.crcWithInverseBit(ab, inverseDirection ? inverseBitByteIndex : -1 );
int hashSize = _arrayBitmap.length;
currentHashBucket = (crc & 0xfffffff) % hashSize;
hashBucketVars = arrayBuildInVariablesCache[currentHashBucket];
currentByteArray = ab;
currentInverseDirection = inverseDirection;
byte[] abBucket = _arrayBitmap[currentHashBucket];
@ -325,18 +326,15 @@ public abstract class BExpressionContext
_arrayInverse[currentHashBucket] = currentInverseDirection;
_arrayCrc[currentHashBucket] = crc;
_receiver = receiver;
decode( lookupData, currentInverseDirection, currentByteArray );
evaluate( lookupData );
for( int vi=0; vi<buildInVariableIdx.length; vi++ )
{
int idx = buildInVariableIdx[vi];
arrayBuildInVariablesCache[vi][currentHashBucket] = idx == -1 ? 0.f : variableData[idx];
hashBucketVars[vi] = idx == -1 ? 0.f : variableData[idx];
}
_receiver = null;
return false;
}
@ -763,9 +761,4 @@ public abstract class BExpressionContext
return value;
}
void expressionWarning( String message )
{
_arrayBitmap[currentHashBucket] = null; // no caching if warnings
if ( _receiver != null ) _receiver.expressionWarning( context, message );
}
}

View file

@ -50,11 +50,11 @@ public final class BExpressionContextWay extends BExpressionContext implements T
@Override
public int accessType( byte[] description )
{
evaluate( false, description, null );
evaluate( false, description );
float minCostFactor = getCostfactor();
if ( minCostFactor >= 9999.f )
{
evaluate( true, description, null );
evaluate( true, description );
float reverseCostFactor = getCostfactor();
if ( reverseCostFactor < minCostFactor )
{

View file

@ -1,7 +0,0 @@
package btools.expressions;
public interface BExpressionReceiver
{
public void expressionWarning( String context, String message );
}

View file

@ -39,7 +39,7 @@ public class EncodeDecodeTest
byte[] description = expctxWay.encode(lookupData);
// calculate the cost factor from that description
expctxWay.evaluate( false, description, null );
expctxWay.evaluate( false, description );
float costfactor = expctxWay.getCostfactor();
Assert.assertTrue( "costfactor mismatch", Math.abs( costfactor - 5.15 ) < 0.00001 );