-
Notifications
You must be signed in to change notification settings - Fork 38
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
perf: add heap benchmark and reduce allocations #1156
Changes from 5 commits
17578fd
fae1582
e68f221
54ec304
c370a1f
02d57b3
c3a5434
38975fb
d4a85f0
c81c7d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,15 @@ | |
@SuppressWarnings({ "PMD.BeanMembersShouldSerialize", "checkstyle:MissingJavadocType" }) | ||
abstract class AbstractStructure implements Structure { | ||
|
||
protected final Map<String, Value> attributes; | ||
private Map<String, Value> attributes; | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return attributes == null || attributes.size() == 0; | ||
} | ||
|
||
AbstractStructure() { | ||
this.attributes = new HashMap<>(); | ||
// intentionally don't initialize the attributes - do this lazily | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted for: #1156 (comment) |
||
} | ||
|
||
AbstractStructure(Map<String, Value> attributes) { | ||
|
@@ -32,4 +37,11 @@ public Map<String, Object> asObjectMap() { | |
(accumulated, entry) -> accumulated.put(entry.getKey(), convertValue(entry.getValue())), | ||
HashMap::putAll); | ||
} | ||
|
||
protected Map<String, Value> getAttributes() { | ||
if (attributes == null) { | ||
attributes = new HashMap<>(); | ||
} | ||
return attributes; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perf: lazily initialize. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes it non thread safe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent point. I've reverted this because it's not a even a substantial savings. The bench result barely changes. |
||
} |
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 don't care if we commit this or not, but I think we should for records.