New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change the way to caculate the size of string #7
Conversation
Please merge the following commit and run We want to make sure that we do not degrade the performance since this function is called repeatedly, possibly millions of times. It also does something that is relatively unimportant (produce a memory usage estimation) so we do not ever want it to have an impact on performance. Here is what it might look like...
|
long offset= unsafe.objectFieldOffset(f); | ||
maxSize=Math.max(maxSize,offset); | ||
} | ||
return (maxSize/8+1)*8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the figure "8" here assumes are 64-bit JVM.
* @param s The string to estimate memory footprint. | ||
* @return The <strong>estimated</strong> size in bytes. | ||
*/ | ||
public static long estimatedSizeOf(String s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am very concerned about the performance of this function. We designed the estimator to be dirt cheap ((s.length() * 2) + OBJ_OVERHEAD
). You are proposing something that looks much more expensive. See my comments on the PR about benchmarking this function.
As the name implies, I think we want an estimation, and we want to get it in not much more than 1 ns on a desktop PC.
I an going to close this since the submitter never got back to us. |
I think this way is better