improve multi value field cache handling both in terms of memory usage and GC behavior

This commit is contained in:
kimchy 2011-01-10 20:58:31 +02:00
parent 233ed1f8c6
commit 89314f29a7
1 changed files with 85 additions and 47 deletions

View File

@ -86,98 +86,136 @@ public class MultiValueGeoPointFieldData extends GeoPointFieldData {
} }
@Override public boolean hasValue(int docId) { @Override public boolean hasValue(int docId) {
return ordinals[docId] != null; for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) {
return true;
}
}
return false;
} }
@Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) { @Override public void forEachValueInDoc(int docId, StringValueInDocProc proc) {
int[] docOrders = ordinals[docId]; for (int[] ordinal : ordinals) {
if (docOrders == null) { int loc = ordinal[docId];
return; if (loc != 0) {
} proc.onValue(docId, GeoHashUtils.encode(lat[loc], lon[loc]));
for (int docOrder : docOrders) { }
proc.onValue(docId, GeoHashUtils.encode(lat[docOrder], lon[docOrder]));
} }
} }
@Override public GeoPoint value(int docId) { @Override public GeoPoint value(int docId) {
int[] docOrders = ordinals[docId]; for (int[] ordinal : ordinals) {
if (docOrders == null) { int loc = ordinal[docId];
return null; if (loc != 0) {
GeoPoint point = valuesCache.get().get();
point.latlon(lat[loc], lon[loc]);
return point;
}
} }
GeoPoint point = valuesCache.get().get(); return null;
int loc = docOrders[0];
point.latlon(lat[loc], lon[loc]);
return point;
} }
@Override public GeoPoint[] values(int docId) { @Override public GeoPoint[] values(int docId) {
int[] docOrders = ordinals[docId]; int length = 0;
if (docOrders == null) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) {
length++;
}
}
if (length == 0) {
return EMPTY_ARRAY; return EMPTY_ARRAY;
} }
GeoPoint[] points; GeoPoint[] points;
if (docOrders.length < VALUE_CACHE_SIZE) { if (length < VALUE_CACHE_SIZE) {
points = valuesArrayCache.get().get()[docOrders.length]; points = valuesArrayCache.get().get()[length];
for (int i = 0; i < docOrders.length; i++) { int i = 0;
int loc = docOrders[i]; for (int[] ordinal : ordinals) {
points[i].latlon(lat[loc], lon[loc]); int loc = ordinal[docId];
if (loc != 0) {
points[i++].latlon(lat[loc], lon[loc]);
}
} }
} else { } else {
points = new GeoPoint[docOrders.length]; points = new GeoPoint[length];
for (int i = 0; i < docOrders.length; i++) { int i = 0;
int loc = docOrders[i]; for (int[] ordinal : ordinals) {
points[i] = new GeoPoint(lat[loc], lon[loc]); int loc = ordinal[docId];
if (loc != 0) {
points[i++] = new GeoPoint(lat[loc], lon[loc]);
}
} }
} }
return points; return points;
} }
@Override public double latValue(int docId) { @Override public double latValue(int docId) {
int[] docOrders = ordinals[docId]; for (int[] ordinal : ordinals) {
if (docOrders == null) { int loc = ordinal[docId];
return 0; if (loc != 0) {
return lat[loc];
}
} }
return lat[docOrders[0]]; return 0;
} }
@Override public double lonValue(int docId) { @Override public double lonValue(int docId) {
int[] docOrders = ordinals[docId]; for (int[] ordinal : ordinals) {
if (docOrders == null) { int loc = ordinal[docId];
return 0; if (loc != 0) {
return lon[loc];
}
} }
return lon[docOrders[0]]; return 0;
} }
@Override public double[] latValues(int docId) { @Override public double[] latValues(int docId) {
int[] docOrders = ordinals[docId]; int length = 0;
if (docOrders == null) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) {
length++;
}
}
if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }
double[] doubles; double[] doubles;
if (docOrders.length < VALUE_CACHE_SIZE) { if (length < VALUE_CACHE_SIZE) {
doubles = valuesLatCache.get().get()[docOrders.length]; doubles = valuesLatCache.get().get()[length];
} else { } else {
doubles = new double[docOrders.length]; doubles = new double[length];
} }
for (int i = 0; i < docOrders.length; i++) { int i = 0;
doubles[i] = lat[docOrders[i]]; for (int[] ordinal : ordinals) {
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = lat[loc];
}
} }
return doubles; return doubles;
} }
@Override public double[] lonValues(int docId) { @Override public double[] lonValues(int docId) {
int[] docOrders = ordinals[docId]; int length = 0;
if (docOrders == null) { for (int[] ordinal : ordinals) {
if (ordinal[docId] != 0) {
length++;
}
}
if (length == 0) {
return DoubleFieldData.EMPTY_DOUBLE_ARRAY; return DoubleFieldData.EMPTY_DOUBLE_ARRAY;
} }
double[] doubles; double[] doubles;
if (docOrders.length < VALUE_CACHE_SIZE) { if (length < VALUE_CACHE_SIZE) {
doubles = valuesLonCache.get().get()[docOrders.length]; doubles = valuesLonCache.get().get()[length];
} else { } else {
doubles = new double[docOrders.length]; doubles = new double[length];
} }
for (int i = 0; i < docOrders.length; i++) { int i = 0;
doubles[i] = lon[docOrders[i]]; for (int[] ordinal : ordinals) {
int loc = ordinal[docId];
if (loc != 0) {
doubles[i++] = lon[loc];
}
} }
return doubles; return doubles;
} }