decoding performance

This commit is contained in:
Arndt Brenschede 2019-06-29 10:11:59 +02:00
parent 7b4db81c78
commit 828227f59d
6 changed files with 65 additions and 46 deletions

View file

@ -62,7 +62,7 @@ public final class MicroCache2 extends MicroCache
if ( debug ) System.out.println( "*** decoding cache of size=" + size + " for lonIdx=" + lonIdx + " latIdx=" + latIdx ); if ( debug ) System.out.println( "*** decoding cache of size=" + size + " for lonIdx=" + lonIdx + " latIdx=" + latIdx );
bc.decodeSortedArray( faid, 0, size, 0x20000000, 0 ); bc.decodeSortedArray( faid, 0, size, 29, 0 );
for( int n = 0; n<size; n++ ) for( int n = 0; n<size; n++ )
{ {

View file

@ -269,22 +269,18 @@ public final class StatCoderContext extends BitCoderContext
* @param value * @param value
* should be 0 * should be 0
*/ */
public void decodeSortedArray( int[] values, int offset, int subsize, int nextbit, int value ) public void decodeSortedArray( int[] values, int offset, int subsize, int nextbitpos, int value )
{ {
if ( subsize == 1 ) // last-choice shortcut if ( subsize == 1 ) // last-choice shortcut
{ {
while (nextbit != 0) if ( nextbitpos >= 0 )
{ {
if ( decodeBit() ) value |= decodeBitsReverse( nextbitpos+1 );
{
value |= nextbit;
}
nextbit >>= 1;
} }
values[offset] = value; values[offset] = value;
return; return;
} }
if ( nextbit == 0 ) if ( nextbitpos < 0 )
{ {
while (subsize-- > 0) while (subsize-- > 0)
{ {
@ -298,11 +294,11 @@ public final class StatCoderContext extends BitCoderContext
if ( size1 > 0 ) if ( size1 > 0 )
{ {
decodeSortedArray( values, offset, size1, nextbit >> 1, value ); decodeSortedArray( values, offset, size1, nextbitpos-1, value );
} }
if ( size2 > 0 ) if ( size2 > 0 )
{ {
decodeSortedArray( values, offset + size1, size2, nextbit >> 1, value | nextbit ); decodeSortedArray( values, offset + size1, size2, nextbitpos-1, value | (1 << nextbitpos) );
} }
} }

View file

@ -13,7 +13,7 @@ public class StatCoderContextTest
{ {
byte[] ab = new byte[40000]; byte[] ab = new byte[40000];
StatCoderContext ctx = new StatCoderContext( ab ); StatCoderContext ctx = new StatCoderContext( ab );
for ( int noisybits = 0; noisybits < 12; noisybits++ ) for ( int noisybits = 1; noisybits < 12; noisybits++ )
{ {
for ( int i = 0; i < 1000; i++ ) for ( int i = 0; i < 1000; i++ )
{ {
@ -22,7 +22,7 @@ public class StatCoderContextTest
} }
ctx = new StatCoderContext( ab ); ctx = new StatCoderContext( ab );
for ( int noisybits = 0; noisybits < 12; noisybits++ ) for ( int noisybits = 1; noisybits < 12; noisybits++ )
{ {
for ( int i = 0; i < 1000; i++ ) for ( int i = 0; i < 1000; i++ )
{ {
@ -114,7 +114,7 @@ public class StatCoderContextTest
ctx = new StatCoderContext( ab ); ctx = new StatCoderContext( ab );
int[] decodedValues = new int[size]; int[] decodedValues = new int[size];
ctx.decodeSortedArray( decodedValues, 0, size, 0x08000000, 0 ); ctx.decodeSortedArray( decodedValues, 0, size, 27, 0 );
for ( int i = 0; i < size; i++ ) for ( int i = 0; i < size; i++ )
{ {

View file

@ -16,20 +16,15 @@ import btools.util.IByteArrayUnifier;
*/ */
public final class DirectWeaver extends ByteDataWriter public final class DirectWeaver extends ByteDataWriter
{ {
private int lonBase; private long id64Base;
private int latBase;
private int cellsize;
private int size = 0; private int size = 0;
private static boolean debug = false;
public DirectWeaver( DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception public DirectWeaver( DataBuffers dataBuffers, int lonIdx, int latIdx, int divisor, TagValueValidator wayValidator, WaypointMatcher waypointMatcher, OsmNodesMap hollowNodes ) throws Exception
{ {
super( null ); super( null );
cellsize = 1000000 / divisor; int cellsize = 1000000 / divisor;
lonBase = lonIdx*cellsize; id64Base = ((long)(lonIdx*cellsize))<<32 | (latIdx*cellsize);
latBase = latIdx*cellsize;
StatCoderContext bc = new StatCoderContext( dataBuffers.iobuffer ); StatCoderContext bc = new StatCoderContext( dataBuffers.iobuffer );
@ -45,9 +40,7 @@ public final class DirectWeaver extends ByteDataWriter
int[] faid = size > dataBuffers.ibuf2.length ? new int[size] : dataBuffers.ibuf2; int[] faid = size > dataBuffers.ibuf2.length ? new int[size] : dataBuffers.ibuf2;
if ( debug ) System.out.println( "*** decoding cache of size=" + size + " for lonIdx=" + lonIdx + " latIdx=" + latIdx ); bc.decodeSortedArray( faid, 0, size, 29, 0 );
bc.decodeSortedArray( faid, 0, size, 0x20000000, 0 );
OsmNode[] nodes = new OsmNode[size]; OsmNode[] nodes = new OsmNode[size];
for( int n = 0; n<size; n++ ) for( int n = 0; n<size; n++ )
@ -59,7 +52,6 @@ public final class DirectWeaver extends ByteDataWriter
if ( node == null ) if ( node == null )
{ {
node = new OsmNode( ilon, ilat ); node = new OsmNode( ilon, ilat );
node.visitID = 0;
} }
else else
{ {
@ -116,7 +108,6 @@ public final class DirectWeaver extends ByteDataWriter
node.nodeDescription = nodeTags == null ? null : nodeTags.data; // TODO: unified? node.nodeDescription = nodeTags == null ? null : nodeTags.data; // TODO: unified?
int links = bc.decodeNoisyNumber( 1 ); int links = bc.decodeNoisyNumber( 1 );
if ( debug ) System.out.println( "*** decoding node " + ilon + "/" + ilat + " with links=" + links );
for( int li=0; li<links; li++ ) for( int li=0; li<links; li++ )
{ {
int nodeIdx = n + nodeIdxDiff.decodeSignedValue(); int nodeIdx = n + nodeIdxDiff.decodeSignedValue();
@ -136,7 +127,6 @@ public final class DirectWeaver extends ByteDataWriter
dlon_remaining = extLonDiff.decodeSignedValue(); dlon_remaining = extLonDiff.decodeSignedValue();
dlat_remaining = extLatDiff.decodeSignedValue(); dlat_remaining = extLatDiff.decodeSignedValue();
} }
if ( debug ) System.out.println( "*** decoding link to " + (ilon+dlon_remaining) + "/" + (ilat+dlat_remaining) + " extern=" + (nodeIdx == n) );
TagValueWrapper wayTags = wayTagCoder.decodeTagValueSet(); TagValueWrapper wayTags = wayTagCoder.decodeTagValueSet();
@ -157,7 +147,6 @@ public final class DirectWeaver extends ByteDataWriter
} }
int transcount = bc.decodeVarBits(); int transcount = bc.decodeVarBits();
if ( debug ) System.out.println( "*** decoding geometry with count=" + transcount );
int count = transcount+1; int count = transcount+1;
for( int i=0; i<transcount; i++ ) for( int i=0; i<transcount; i++ )
{ {
@ -212,7 +201,21 @@ public final class DirectWeaver extends ByteDataWriter
hollowNodes.cleanupAndCount( nodes ); hollowNodes.cleanupAndCount( nodes );
} }
public long expandId( int id32 ) private static final long[] id32_00 = new long[1024];
private static final long[] id32_10 = new long[1024];
private static final long[] id32_20 = new long[1024];
static
{
for( int i=0; i<1024; i++ )
{
id32_00[i] = _expandId( i );
id32_10[i] = _expandId( i << 10 );
id32_20[i] = _expandId( i << 20 );
}
}
private static long _expandId( int id32 )
{ {
int dlon = 0; int dlon = 0;
int dlat = 0; int dlat = 0;
@ -223,11 +226,11 @@ public final class DirectWeaver extends ByteDataWriter
if ( (id32 & 2) != 0 ) dlat |= bm; if ( (id32 & 2) != 0 ) dlat |= bm;
id32 >>= 2; id32 >>= 2;
} }
return ((long)dlon)<<32 | dlat;
int lon32 = lonBase + dlon;
int lat32 = latBase + dlat;
return ((long)lon32)<<32 | lat32;
} }
public long expandId( int id32 )
{
return id64Base + id32_00[ id32 & 1023 ] + id32_10[ (id32>>10) & 1023 ] + id32_20[ (id32>>20) & 1023 ];
}
} }

View file

@ -46,7 +46,7 @@ public class OsmNode extends OsmLink implements OsmPos
/** /**
* The links to other nodes * The links to other nodes
*/ */
public OsmLink firstlink = null; public OsmLink firstlink;
public OsmNode() public OsmNode()
{ {
@ -303,12 +303,7 @@ public class OsmNode extends OsmLink implements OsmPos
@Override @Override
public final boolean equals( Object o ) public final boolean equals( Object o )
{ {
if ( o instanceof OsmNode ) return ((OsmNode)o).ilon == ilon && ((OsmNode)o).ilat == ilat;
{
OsmNode n = (OsmNode) o;
return n.ilon == ilon && n.ilat == ilat;
}
return false;
} }
@Override @Override

View file

@ -13,6 +13,8 @@ public class BitCoderContext
private static final int[] vl_values = new int[4096]; private static final int[] vl_values = new int[4096];
private static final int[] vl_length = new int[4096]; private static final int[] vl_length = new int[4096];
private static final int[] reverse_byte = new int[256];
static static
{ {
// fill varbits lookup table // fill varbits lookup table
@ -28,6 +30,15 @@ public class BitCoderContext
vl_values[i] = bc.decodeVarBits2(); vl_values[i] = bc.decodeVarBits2();
vl_length[i] = bc.getReadingBitPosition() - b0; vl_length[i] = bc.getReadingBitPosition() - b0;
} }
for( int b=0; b<256; b++ )
{
int r = 0;
for( int i=0; i<8; i++ )
{
if ( (b & (1<<i) ) != 0 ) r |= 1 << (7-i);
}
reverse_byte[b] = r;
}
} }
@ -190,10 +201,6 @@ public class BitCoderContext
public final int decodeBits( int count ) public final int decodeBits( int count )
{ {
if ( count == 0 )
{
return 0;
}
fillBuffer(); fillBuffer();
int mask = 0xffffffff >>> ( 32 - count ); int mask = 0xffffffff >>> ( 32 - count );
int value = b & mask; int value = b & mask;
@ -202,6 +209,24 @@ public class BitCoderContext
return value; return value;
} }
public final int decodeBitsReverse( int count )
{
fillBuffer();
int value = 0;
while( count > 8 )
{
value = (value << 8) | reverse_byte[ b & 0xff ];
b >>=8;
count -=8;
bits -=8;
fillBuffer();
}
value = (value << count) | reverse_byte[ b & 0xff ] >> (8-count);
bits -= count;
b >>= count;
return value;
}
private void fillBuffer() private void fillBuffer()
{ {
while (bits < 24) while (bits < 24)