Skip to content
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

Optimize performance of SlotMap a bit #1670

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented Oct 2, 2024

This is a small improvement, but I imagine it is measurable

@@ -257,9 +256,8 @@ private static void copyTable(Slot[] oldSlots, Slot[] newSlots) {
*/
private static void addKnownAbsentSlot(Slot[] addSlots, Slot slot) {
final int insertPos = getSlotIndex(addSlots.length, slot.indexOrHash);
Slot old = addSlots[insertPos];
slot.next = addSlots[insertPos];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both changes in embeddedSlotMap save ~ 5 bytecode instructions: https://godbolt.org/z/1EjhsWs7E

@@ -82,7 +82,7 @@ int getAttributes() {
return attributes;
}

synchronized void setAttributes(int value) {
void setAttributes(int value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you should use "synchronized" here. attributes is not a long or double and write should be atomic: https://docs.oracle.com/javase/specs/jls/se9/html/jls-17.html#jls-17.7

(even if it is a long/double, it would be atomic on 64bit jvms)

@gbrail
Copy link
Collaborator

gbrail commented Oct 2, 2024 via email

@gbrail
Copy link
Collaborator

gbrail commented Oct 3, 2024

FWIW this didn't result in any measurable changes (Java does a ton of optimization of bytecode including making uncontended synchronization very cheap). But if you all think it makes sense -- less bytecode is always good -- I'm happy to merge it.

@gbrail gbrail merged commit 292d45e into mozilla:master Oct 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants