Skip to content

Optimize ExecutionAttributes#6910

Merged
alextwoods merged 3 commits intomasterfrom
alexwoo/execattr_opt
Apr 27, 2026
Merged

Optimize ExecutionAttributes#6910
alextwoods merged 3 commits intomasterfrom
alexwoo/execattr_opt

Conversation

@alextwoods
Copy link
Copy Markdown
Contributor

Optimize ExecutionAttributes to reduce resizes and reduce hash computation cost

Motivation and Context

Fixes: #6846

Modifications

There are two modifications:

  1. Increase the initial capacity to 64. In most requests I tested we had around 45 execution attributes, so this prevents resizing for those requests.
  2. Switch to using IdentityHashMap, which uses == instead of the string hash code.

IdentityHashMap uses == instead of .equals() for key comparison. This is safe for ExecutionAttributes because all keys are enforced singletons. ExecutionAttribute.ensureUnique() throws IllegalArgumentException if you try to create a second instance with the same name. Every ExecutionAttribute in the SDK is declared static final.

The change is internal. The field type is still Map<ExecutionAttribute<?>, Object>, and getAttributes() wraps it in Collections.unmodifiableMap(), so callers are unaffected.

Testing

All existing tests.

Performance

The combined optimization (IdentityHashMap + capacity 64)
provides a modest but measurable improvement:

  • Eliminates 1 HashMap resize per request (saves ~0.5-1% CPU)
  • Eliminates String-based hashCode computation for all attribute lookups (saves ~0.3% CPU)
  • Reduces Node object allocation (IdentityHashMap uses flat array)
  • Total: ~1-2% CPU reduction in the ExecutionAttributes hot path

ops/cpu-second for a high throughput dynamodb workload (running on a c7g.8xlarge):

optimized: 3255.4414101
baseline: 3186.2756065
Improvement: 2.17%

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.

License

  • I confirm that this pull request can be released under the Apache 2 license

@alextwoods alextwoods requested a review from a team as a code owner April 27, 2026 16:25
@alextwoods alextwoods added the perf-improvement Label for PRs that contain performance improvement changes. label Apr 27, 2026
@alextwoods alextwoods added the no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required label Apr 27, 2026
@alextwoods alextwoods enabled auto-merge April 27, 2026 16:51
@alextwoods alextwoods added this pull request to the merge queue Apr 27, 2026
Merged via the queue into master with commit 760c132 Apr 27, 2026
14 of 16 checks passed
@github-actions
Copy link
Copy Markdown

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 27, 2026
@alextwoods alextwoods deleted the alexwoo/execattr_opt branch April 27, 2026 18:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required perf-improvement Label for PRs that contain performance improvement changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExecutionAttributes default HashMap capacity causes repeated resize during every DynamoDB request

2 participants