mirror of https://github.com/apache/lucene.git
LUCENE-10129: Add RamUsageEstimator.shallowSizeOf() for primitive arrays (#367)
Co-authored-by: Stefan Vodita <voditas@amazon.com>
This commit is contained in:
parent
c9e56d27a3
commit
560f71b47d
|
@ -163,6 +163,10 @@ API Changes
|
|||
|
||||
Improvements
|
||||
|
||||
* LUCENE-10129: RamUsageEstimator overloads the shallowSizeOf method for primitive arrays
|
||||
to avoid falling back on shallowSizeOf(Object), which could lead to performance traps.
|
||||
(Robert Muir, Uwe Schindler, Stefan Vodita)
|
||||
|
||||
* LUCENE-10139: ExternalRefSorter returns a covariant with a subtype of BytesRefIterator
|
||||
that is Closeable. (Dawid Weiss).
|
||||
|
||||
|
|
|
@ -486,6 +486,46 @@ public final class RamUsageEstimator {
|
|||
return alignObjectSize(size);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the byte[] object. */
|
||||
public static long shallowSizeOf(byte[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the boolean[] object. */
|
||||
public static long shallowSizeOf(boolean[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the char[] object. */
|
||||
public static long shallowSizeOf(char[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the short[] object. */
|
||||
public static long shallowSizeOf(short[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the int[] object. */
|
||||
public static long shallowSizeOf(int[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the float[] object. */
|
||||
public static long shallowSizeOf(float[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the long[] object. */
|
||||
public static long shallowSizeOf(long[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the size in bytes of the double[] object. */
|
||||
public static long shallowSizeOf(double[] arr) {
|
||||
return sizeOf(arr);
|
||||
}
|
||||
|
||||
/** Returns the shallow size in bytes of the Object[] object. */
|
||||
// Use this method instead of #shallowSizeOf(Object) to avoid costly reflection
|
||||
public static long shallowSizeOf(Object[] arr) {
|
||||
|
|
|
@ -65,41 +65,49 @@ public class TestRamUsageEstimator extends LuceneTestCase {
|
|||
{
|
||||
byte[] array = new byte[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
boolean[] array = new boolean[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
char[] array = new char[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
short[] array = new short[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
int[] array = new int[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
float[] array = new float[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
long[] array = new long[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
|
||||
{
|
||||
double[] array = new double[rnd.nextInt(1024)];
|
||||
assertEquals(sizeOf(array), sizeOf((Object) array));
|
||||
assertEquals(shallowSizeOf(array), sizeOf((Object) array));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue