Skip to content

Commit

Permalink
Add RamUsageEstimator#sizeOf(Object) to forbidden APIs
Browse files Browse the repository at this point in the history
This method can be a performance trap since it traverse the
entire object tree that is referenced by the provided object.
See LUCENE-5373
  • Loading branch information
s1monw committed Jan 31, 2014
1 parent 6e18a89 commit 9cf8251
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core-signatures.txt
Expand Up @@ -17,3 +17,6 @@ java.util.Collections#sort(java.util.List)
java.util.Collections#sort(java.util.List,java.util.Comparator)

java.io.StringReader#<init>(java.lang.String) @ Use FastStringReader instead

org.apache.lucene.util.RamUsageEstimator#sizeOf(java.lang.Object) @ This can be a perfromance trap

1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -982,6 +982,7 @@
<exclude>org/elasticsearch/plugins/PluginManager.class</exclude>
<exclude>org/elasticsearch/bootstrap/Bootstrap.class</exclude>
<exclude>org/elasticsearch/Version.class</exclude>
<exclude>org/elasticsearch/index/percolator/stats/ShardPercolateService$RamEstimator.class</exclude>
<!-- end excludes for valid system-out -->
<!-- start excludes for Unsafe -->
<exclude>org/elasticsearch/common/util/UnsafeUtils.class</exclude>
Expand Down
Expand Up @@ -86,8 +86,16 @@ public PercolateStats stats() {

private static long computeSizeInMemory(HashedBytesRef id, Query query) {
long size = (3 * RamUsageEstimator.NUM_BYTES_INT) + RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + id.bytes.bytes.length;
size += RamUsageEstimator.sizeOf(query);
size += RamEstimator.sizeOf(query);
return size;
}

private static final class RamEstimator {
// we move this into it's own class to exclude it from the forbidden API checks
// it's fine to use here!
static long sizeOf(Query query) {
return RamUsageEstimator.sizeOf(query);
}
}

}

0 comments on commit 9cf8251

Please sign in to comment.