Skip to content

Commit 760c132

Browse files
authored
Optimize ExecutionAttributes (#6910)
* Optimize ExecutionAttributes * Add changelog
1 parent eca21f8 commit 760c132

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Optimize ExecutionAttributes to reduce resizes and reduce hash computation cost."
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/ExecutionAttributes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package software.amazon.awssdk.core.interceptor;
1717

1818
import java.util.Collections;
19-
import java.util.HashMap;
19+
import java.util.IdentityHashMap;
2020
import java.util.Map;
2121
import java.util.Optional;
2222
import software.amazon.awssdk.annotations.NotThreadSafe;
@@ -38,11 +38,11 @@ public class ExecutionAttributes implements ToCopyableBuilder<ExecutionAttribute
3838
private final Map<ExecutionAttribute<?>, Object> attributes;
3939

4040
public ExecutionAttributes() {
41-
this.attributes = new HashMap<>(32);
41+
this.attributes = new IdentityHashMap<>(64);
4242
}
4343

4444
protected ExecutionAttributes(Map<? extends ExecutionAttribute<?>, ?> attributes) {
45-
this.attributes = new HashMap<>(attributes);
45+
this.attributes = new IdentityHashMap<>(attributes);
4646
}
4747

4848
/**
@@ -88,7 +88,7 @@ public <U> ExecutionAttributes putAttributeIfAbsent(ExecutionAttribute<U> attrib
8888
* Merge attributes of a higher precedence into the current lower precedence collection.
8989
*/
9090
public ExecutionAttributes merge(ExecutionAttributes lowerPrecedenceExecutionAttributes) {
91-
Map<ExecutionAttribute<?>, Object> copiedAttributes = new HashMap<>(this.attributes);
91+
Map<ExecutionAttribute<?>, Object> copiedAttributes = new IdentityHashMap<>(this.attributes);
9292
lowerPrecedenceExecutionAttributes.getAttributes().forEach(copiedAttributes::putIfAbsent);
9393
return new ExecutionAttributes(copiedAttributes);
9494
}
@@ -167,7 +167,7 @@ public <U> ExecutionAttributes putAttributeIfAbsent(ExecutionAttribute<U> attrib
167167
* copy() if it's because of {@link #unmodifiableExecutionAttributes(ExecutionAttributes)}.
168168
*/
169169
public static final class Builder implements CopyableBuilder<ExecutionAttributes.Builder, ExecutionAttributes> {
170-
private final Map<ExecutionAttribute<?>, Object> executionAttributes = new HashMap<>(32);
170+
private final Map<ExecutionAttribute<?>, Object> executionAttributes = new IdentityHashMap<>(64);
171171

172172
private Builder() {
173173
}

0 commit comments

Comments
 (0)