You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "smuching202 (via GitHub)" <gi...@apache.org> on 2025/07/31 15:45:18 UTC

[I] BytesRefIntMap's INIT_RAM_BYTES uses shallowSizeof() instead of shallowSizeOfInstance() [lucene]

smuching202 opened a new issue, #15018:
URL: https://github.com/apache/lucene/issues/15018

   I noticed that ByteRefIntMap's INIT_RAM_BYTES [assignment](https://github.com/apache/lucene/blob/branch_10_2/lucene/core/src/java/org/apache/lucene/index/BufferedUpdates.java#L295) uses `RamUsageEstimator.shallowSizeOf` with a class literal, which seems incorrect:
   
   ```
   private static final long INIT_RAM_BYTES =
       RamUsageEstimator.shallowSizeOf(BytesRefIntMap.class)
           + RamUsageEstimator.shallowSizeOf(BytesRefHash.class)
           + RamUsageEstimator.sizeOf(new int[BytesRefHash.DEFAULT_CAPACITY]);
   ```
   
   If we follow the flow for `RamUsageEstimator.shallowSizeOf(BytesRefIntMap.class)`, and look at the [implementation](https://github.com/apache/lucene/blob/branch_10_2/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java#L517), it expects an object instance as its parameter:
   
   ```
   public static long shallowSizeOf(Object obj) {
     if (obj == null) return 0;
     final Class<?> clz = obj.getClass();
     if (clz.isArray()) {
       return shallowSizeOfArray(obj);
     } else {
       return shallowSizeOfInstance(clz);
     }
   }
   ```
   
   Passing a class literal (e.g., BytesRefIntMap.class) means obj.getClass() will return java.lang.Class, so this code is actually measuring the size of a Class object, not the shallow size of a BytesRefIntMap instance.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [I] BytesRefIntMap's INIT_RAM_BYTES uses shallowSizeof() instead of shallowSizeOfInstance() [lucene]

Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss closed issue #15018: BytesRefIntMap's INIT_RAM_BYTES uses shallowSizeof() instead of shallowSizeOfInstance()
URL: https://github.com/apache/lucene/issues/15018


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [I] BytesRefIntMap's INIT_RAM_BYTES uses shallowSizeof() instead of shallowSizeOfInstance() [lucene]

Posted by "gf2121 (via GitHub)" <gi...@apache.org>.
gf2121 commented on issue #15018:
URL: https://github.com/apache/lucene/issues/15018#issuecomment-3143231272

   Hi, i think this is a bug (my bad), thanks for catching!
   
   Would you like to open a PR to fix?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [I] BytesRefIntMap's INIT_RAM_BYTES uses shallowSizeof() instead of shallowSizeOfInstance() [lucene]

Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on issue #15018:
URL: https://github.com/apache/lucene/issues/15018#issuecomment-3200344098

   Good catch!  Can we somehow forbid this accidental application (calling `RamUsageEstimator.shallowSizeOff(Class)`?  Do we do this in other places?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org