Skip to content

[Fix #10460]: Pre-size ProxyContext map to avoid HashMap resize on request path#10461

Open
HarshMehta112 wants to merge 3 commits into
apache:developfrom
HarshMehta112:develop
Open

[Fix #10460]: Pre-size ProxyContext map to avoid HashMap resize on request path#10461
HarshMehta112 wants to merge 3 commits into
apache:developfrom
HarshMehta112:develop

Conversation

@HarshMehta112

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Brief Description

ProxyContext is created on every gRPC/Remoting request. Its value map used the default HashMap capacity (16, threshold 12), so adding the 10 ContextVariable keys plus interceptor entries triggers a
resize on the hot path. Pre-size the map to avoid it:

private static final int DEFAULT_INITIAL_CAPACITY = 64;
private final Map<String, Object> value = new HashMap<>(DEFAULT_INITIAL_CAPACITY);

No behavior or API change.

How Did You Test This Change?

Pure capacity refactor, no logic change. Existing proxy module tests pass.

Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>

@oss-sentinel-ai oss-sentinel-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: Approved ✅

PR: #10461 — [Fix #10460]: Pre-size ProxyContext map to avoid HashMap resize on request path
Type: Performance optimization (1 file, +2/-1)

Assessment

Valid performance fix. ProxyContext is created per gRPC/Remoting request, and its value map previously used the default HashMap capacity (16, threshold 12). Adding ~10 ContextVariable keys plus interceptor entries would trigger a resize on the hot path.

Changes

  • Pre-sized HashMap to 64 (threshold 48), well above the expected key count
  • Minimal, focused change with no API impact

Verdict

✅ Clean, well-targeted optimization. Fixes #10460.


🤖 Automated review by oss-sentinel-ai

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.99%. Comparing base (2319d2f) to head (f7fe3db).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10461      +/-   ##
=============================================
- Coverage      48.11%   47.99%   -0.12%     
+ Complexity     13329    13289      -40     
=============================================
  Files           1377     1377              
  Lines         100632   100632              
  Branches       12995    12995              
=============================================
- Hits           48422    48302     -120     
- Misses         46289    46385      +96     
- Partials        5921     5945      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[Enhancement] Set initial capacity for ProxyContext internal HashMap to avoid resize

3 participants