Repository navigation
Conversation
…after after() concatenated Constants.PLUGIN_START_TIME + named() twice — once to read the start time and once to remove it — allocating a new String for every executed plugin on every request. Build the key once in a local variable and use it for both operations; the attribute key, the debug log and the lifecycle (including the loud failure when after runs without before) are unchanged.
The assertion only checks that the attribute is removed, which does not depend on the elapsed time.
wy471x
left a comment
There was a problem hiding this comment.
Review: ShenyuPlugin.after builds the timing key once
Verdict: Approve — ready to merge once the nits below are addressed or consciously deferred.
The change itself is correct and minimal: String timingKey = Constants.PLUGIN_START_TIME + named() is built once and reused for both the get and the remove, the produced key is identical to before, and it removes one allocation per executed plugin per request.
Standards
shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java— the new comment// build the timing key once: this runs for every executed plugin on every request (#8437)restates the next line.copilot-instructions.mdasks comments to explain rationale rather than restate code; the method Javadoc above already covers the lifecycle. Drop the first clause or drop the comment.- Duplicated key construction with
before:beforestill does the same concatenation. Extracting a privatepluginStartTimeKey()helper (Java 17 allows private interface methods) would let both hooks share one definition and keep them from drifting, which is the only way the allocation is removed twice rather than once. afterdoesget(timingKey)and thenremove(timingKey)— two map lookups on a hot path.ShenyuWebHandler.after(shenyu-web/.../ShenyuWebHandler.java) already does the singleattributes.remove(...)form. Keeping the two implementations divergent is acceptable given the "lifecycle unchanged" constraint, butremovereturning the value would have been the natural end state; worth a follow-up rather than a change here.
Spec (#8437)
- The stated contract — same attribute key, same debug log, same lifecycle — holds; no scope creep beyond one test file.
- The new tests are characterization, not a guard for this change: both
beforeRecordsAndAfterRemovesTheTimingAttributeandafterWithoutBeforeKeepsFailingLoudlypass against unmodifiedmaster(the NPE comes from the pre-existing(long)unboxing). That is acceptable for an allocation-only refactor, but the class Javadoc's claim that "the attribute key, the debug log and the lifecycle are unchanged" is only partly pinned: nothing observes theLOG.debugline, the cost value, or the key literal, since the test rebuilds the key with the same expression production uses. Asserting the literal (pluginStartTime:<name>) would make the key claim real. afterWithoutBeforeKeepsFailingLoudlypins an incidentalNullPointerExceptionfrom unboxing. It also locks in a detail that a legitimate future fix (null-guarding likeShenyuWebHandler.afterdoes) would have to fight. Prefer asserting the failure only loosely, or drop the case and let the companion logging/lifecycle PR own it.- No logging test exists, though #8437 says "A PR with lifecycle and logging tests will follow" — fine to defer, but please don't let the class Javadoc imply it is covered today.
Nothing here blocks the merge; the first two points are the ones I would like to see before it goes in.
Aias00
left a comment
There was a problem hiding this comment.
Stream Agent analysis
Behavior-preserving allocation optimization in ShenyuPlugin.after: the timing key is built once and reused for both attribute get and remove; the new unit test pins the record/remove flow and the loud NPE on after-without-before. Full diff read and CI passed.
Evidence
- Full captured diff read (has_more=false, matches attachment): ShenyuPlugin.after builds timingKey=Constants.PLUGIN_START_TIME+named() once, reused for get (RIGHT line 163) and remove (RIGHT line 165); new file ShenyuPluginLifecycleTimingTest.java added.
- Cross-file contract verified via resource_read/search: before() head line 146 and test line 61 use identical PLUGIN_START_TIME+named() key; Constants.PLUGIN_START_TIME='pluginStartTime:' defined; debug log and lifecycle unchanged.
- CI: 70 checks, complete=true, passed=true, all success (e2e, CodeQL, e2e-case matrix).
Recommended next steps
Scope: captured diff and GitHub check metadata only; no local tests were executed.
Task: f3198f26-aa61-4f64-b6cf-c6de7de6e477 · Commit: f79f461122c762621382396fc944b8ca6263754d
Review verdict: PASS
Complete WHOLE_PR coverage: full diff read and verified against head source; the change only removes a redundant String allocation on the hot path while preserving the exact attribute key, debug log, and failure semantics (pinned by a new unit test). No concrete HIGH/CRITICAL defect and CI passed.
Publication: COMMENT (CI_NOT_PASSED)
Closing in favor of the original author's PR (#8432) — apologies for the duplicate: my claim checklist missed the linked PRs, which the issue search surface does not show. The work here added nothing beyond what that PR already covers.