-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
chore: optimize lazy val with power of two. #22428
base: main
Are you sure you want to change the base?
Conversation
@@ -27,17 +27,18 @@ object LazyVals { | |||
|
|||
private val base: Int = { | |||
val processors = java.lang.Runtime.getRuntime.nn.availableProcessors() | |||
8 * processors * processors | |||
val rawSize = 8 * processors * processors |
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.
not sure why it's 8
here, Some CPU has 384 cores now, maybe 2 * 2 is better than 8.
The current implementation may use a little more memory than it was, but as many server just has 64 cores, which is the same.
|
||
if (id < 0) id += base | ||
monitors(id) | ||
monitors((java.lang.System.identityHashCode(obj) + fieldId) & mask) |
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.
Use &
instead of %
Motivation:
Use
&
instead of%
, which is faster.