performance

This commit is contained in:
Arndt Brenschede 2016-09-09 19:42:00 +02:00
parent 62d089ebb5
commit 9d00b0181e
14 changed files with 194 additions and 105 deletions

View file

@ -17,6 +17,8 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -327,14 +329,28 @@ public final class OsmTrack
public void writeGpx( String filename ) throws Exception
{
BufferedWriter bw = new BufferedWriter( new FileWriter( filename ) );
bw.write( formatAsGpx() );
formatAsGpx( bw );
bw.close();
}
public String formatAsGpx()
{
StringBuilder sb = new StringBuilder( 8192 );
try
{
StringWriter sw = new StringWriter( 8192 );
BufferedWriter bw = new BufferedWriter( sw );
formatAsGpx( bw );
bw.close();
return sw.toString();
}
catch( Exception e )
{
throw new RuntimeException( e );
}
}
public String formatAsGpx( BufferedWriter sb ) throws IOException
{
int turnInstructionMode = voiceHints != null ? voiceHints.turnInstructionMode : 0;
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
@ -385,8 +401,8 @@ public final class OsmTrack
sb.append(" <rtept lat=\"").append( formatILat( hint.ilat ) ).append( "\" lon=\"" )
.append( formatILon( hint.ilon ) ).append( "\">\n" )
.append ( " <desc>" ).append( hint.getMessageString() ).append( "</desc>\n <extensions>\n <turn>" )
.append( hint.getCommandString() ).append("</turn>\n <turn-angle>").append( hint.angle )
.append("</turn-angle>\n <offset>").append( hint.indexInTrack ).append("</offset>\n </extensions>\n </rtept>\n");
.append( hint.getCommandString() ).append("</turn>\n <turn-angle>").append( "" + hint.angle )
.append("</turn-angle>\n <offset>").append( "" + hint.indexInTrack ).append("</offset>\n </extensions>\n </rtept>\n");
}
sb.append("</rte>\n");
}
@ -399,8 +415,8 @@ public final class OsmTrack
.append( formatILat( hint.ilat ) ).append( "\">" )
.append( hint.selev == Short.MIN_VALUE ? "" : "<ele>" + (hint.selev / 4.) + "</ele>" )
.append( "<name>" ).append( hint.getMessageString() ).append( "</name>" )
.append( "<extensions><locus:rteDistance>" ).append( hint.distanceToNext ).append( "</locus:rteDistance>" )
.append( "<locus:rtePointAction>" ).append( hint.getLocusAction() ).append( "</locus:rtePointAction></extensions>" )
.append( "<extensions><locus:rteDistance>" ).append( "" + hint.distanceToNext ).append( "</locus:rteDistance>" )
.append( "<locus:rtePointAction>" ).append( "" + hint.getLocusAction() ).append( "</locus:rtePointAction></extensions>" )
.append( "</wpt>\n" );
}
}
@ -425,7 +441,7 @@ public final class OsmTrack
if ( turnInstructionMode == 2 )
{
sb.append( " <extensions><locus:rteComputeType>" ).append( voiceHints.getLocusRouteType() ).append( "</locus:rteComputeType></extensions>\n" );
sb.append( " <extensions><locus:rteComputeType>" ).append( "" + voiceHints.getLocusRouteType() ).append( "</locus:rteComputeType></extensions>\n" );
sb.append( " <extensions><locus:rteSimpleRoundabouts>1</locus:rteSimpleRoundabouts></extensions>\n" );
}

View file

@ -63,8 +63,8 @@ public final class ProfileCache
BExpressionMetaData meta = new BExpressionMetaData();
BExpressionContextGlobal expctxGlobal = new BExpressionContextGlobal( meta );
rc.expctxWay = new BExpressionContextWay( rc.serversizing ? 131072 : 32768, meta );
rc.expctxNode = new BExpressionContextNode( rc.serversizing ? 4096 : 1024, meta );
rc.expctxWay = new BExpressionContextWay( rc.memoryclass * 512, meta );
rc.expctxNode = new BExpressionContextNode( rc.memoryclass * 128, meta );
meta.readMetaData( new File( profileDir, "lookups.dat" ) );

View file

@ -41,7 +41,7 @@ public final class RoutingContext
public BExpressionContextWay expctxWay;
public BExpressionContextNode expctxNode;
public boolean serversizing = false;
public int memoryclass = 64;
public int downhillcostdiv;
public int downhillcutoff;

View file

@ -173,6 +173,7 @@ public class RoutingEngine extends Thread
{
continue;
}
oldTrack = null;
track.writeGpx( filename );
foundTrack = track;
alternativeIndex = i;
@ -573,7 +574,10 @@ public class RoutingEngine extends Thread
logInfo( "NodesCache status before reset=" + nodesCache.formatStatus() );
}
nodesMap = new OsmNodesMap();
nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay, routingContext.forceSecondaryData, nodesCache );
long maxmem = routingContext.memoryclass * 131072L; // 1/4 of total
nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay, routingContext.forceSecondaryData, maxmem, nodesCache );
}
private OsmNode getStartNode( long startId )
@ -699,6 +703,20 @@ public class RoutingEngine extends Thread
}
private OsmTrack findTrack( String operationName, MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack costCuttingTrack, OsmTrack refTrack, boolean fastPartialRecalc )
{
try
{
resetCache();
return _findTrack( operationName, startWp, endWp, costCuttingTrack, refTrack, fastPartialRecalc );
}
finally
{
nodesCache.cleanNonVirgin();
}
}
private OsmTrack _findTrack( String operationName, MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack costCuttingTrack, OsmTrack refTrack, boolean fastPartialRecalc )
{
boolean verbose = guideTrack != null;
@ -711,7 +729,6 @@ public class RoutingEngine extends Thread
matchPath = null;
int nodesVisited = 0;
resetCache();
long endNodeId1 = endWp == null ? -1L : endWp.node1.getIdFromPos();
long endNodeId2 = endWp == null ? -1L : endWp.node2.getIdFromPos();
long startNodeId1 = startWp.node1.getIdFromPos();