Skip to content

[ISSUE #10464] Avoid unnecessary allocation in Message.getProperty and NFE in getPriority#10468

Open
wang-jiahua wants to merge 1 commit into
apache:developfrom
wang-jiahua:perf/message-getproperty-nfe-fix
Open

[ISSUE #10464] Avoid unnecessary allocation in Message.getProperty and NFE in getPriority#10468
wang-jiahua wants to merge 1 commit into
apache:developfrom
wang-jiahua:perf/message-getproperty-nfe-fix

Conversation

@wang-jiahua

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Fixes #10464

Brief Description

Two per-message allocation/CPU fixes in Message.java:

  1. getProperty(String): when properties == null, returns null immediately instead of creating a new HashMap<>() as a side-effect of a read-only call.

  2. getPriority(): adds a null/empty fast-path before delegating to NumberUtils.toInt(). Previously, NumberUtils.toInt(null, -1) internally called Integer.parseInt(null) which throws and catches a NumberFormatException on every invocation (~16,000 NFE/min under benchmark load). The fast-path skips this throw+catch when PRIORITY is unset (the vast majority of messages).

Compatibility

  • getProperty() no longer creates an empty HashMap as a side-effect. Callers that relied on this side-effect to later put directly into properties (without going through putProperty()) would break — but no such callers exist in the codebase (verified by grep).
  • getPriority() return values are unchanged for all inputs.

How Did You Test This Change

mvn -pl common -Dcheckstyle.skip=false -Dspotbugs.skip=true validate
# 0 Checkstyle violations

Existing unit tests pass. The behavioral change in getProperty() is safe because hasProperty() already handles properties == null by returning false, and all write paths go through putProperty() which creates the HashMap on demand.

Copilot AI review requested due to automatic review settings June 10, 2026 14:09

Copilot 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Reduces side effects when reading message properties and makes priority parsing more explicit when the stored value is missing/empty.

Changes:

  • Stop initializing properties on read in getProperty(...) (return null when properties is absent).
  • Add explicit null/empty handling when parsing priority in getPriority().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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: #10468 — Avoid unnecessary allocation in Message.getProperty and NFE in getPriority
Type: Performance (1 file, +6/-3)

Assessment

Fixes two per-message allocation issues:

  • getProperty() returns null immediately when properties is null (no HashMap creation)
  • getPriority() adds null/empty fast-path (eliminates ~16,000 NFE/min)

Verdict

✅ Clean performance fix based on JFR profiling. Fixes #10464.


🤖 Automated review by oss-sentinel-ai

…rty and NFE in getPriority

- getProperty(): return null when properties map is uninitialized instead
  of creating an empty HashMap as a side-effect of a read-only call.
- getPriority(): add null/empty fast-path before NumberUtils.toInt() to
  skip the NFE throw+catch when PRIORITY is unset (the common case).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wang-jiahua wang-jiahua force-pushed the perf/message-getproperty-nfe-fix branch from 64ab982 to 35ebfd6 Compare June 12, 2026 03:30

@RockteMQ-AI RockteMQ-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 by github-manager-bot

Summary

Performance optimization in Message.java: eliminates unnecessary HashMap allocation in getProperty() and avoids NumberFormatException throw+catch in getPriority() when priority is unset.

Findings

  • [Info] getProperty() — Removing the side-effect (creating HashMap on read) is correct. A getter should not mutate state. The Javadoc addition clearly documents the new contract.
  • [Info] getPriority() — The null/empty fast-path before NumberUtils.toInt() is a clean fix. Under high throughput this avoids significant NFE overhead (~16k/min as noted).
  • [Info] Compatibility — The author verified no callers depend on the HashMap creation side-effect. This is safe.

Suggestions

  • Consider adding a unit test for getProperty() when properties == null to prevent regression of the side-effect behavior.
  • Consider a microbenchmark (JMH) for getPriority() to quantify the NFE avoidance improvement.

Overall: Clean, well-documented performance fix. LGTM.


Automated review by github-manager-bot

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] Avoid unnecessary allocation in Message.getProperty and NFE in getPriority

5 participants