Skip to content

fix(plugin-base): short-circuit cached selector and rule matches#6313

Closed
Aias00 wants to merge 4 commits intoapache:masterfrom
Aias00:fix/plugin-cache-short-circuit
Closed

fix(plugin-base): short-circuit cached selector and rule matches#6313
Aias00 wants to merge 4 commits intoapache:masterfrom
Aias00:fix/plugin-cache-short-circuit

Conversation

@Aias00
Copy link
Copy Markdown
Contributor

@Aias00 Aias00 commented Apr 1, 2026

Summary

  • reuse cached selector matches in AbstractShenyuPlugin instead of re-running default selector matching on a cache hit
  • reuse cached rule matches on a cache hit while preserving the existing empty-sentinel fallback behavior
  • add AbstractShenyuPluginTest coverage for selector-cache-hit and rule-cache-hit short-circuit paths

Test Plan

  • ./mvnw -q -pl shenyu-plugin/shenyu-plugin-base -am -Dtest=AbstractShenyuPluginTest -DfailIfNoTests=false -DskipITs -Drat.skip=true -Djacoco.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true test

Copilot AI review requested due to automatic review settings April 1, 2026 02:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the shenyu-plugin-base execution path by actually reusing selector/rule match results from MatchDataCache on cache hits (instead of re-running the default matching logic), and adds unit tests to cover the new short-circuit paths.

Changes:

  • Short-circuit selector matching when a non-empty cached selector hit is present.
  • Short-circuit rule matching when a non-empty cached rule hit is present (while preserving the existing empty-sentinel behavior).
  • Add unit tests for selector/rule cache-hit short-circuit paths; update .gitignore to ignore local worktrees.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java Reuses cached selector/rule matches to avoid re-running default matching on cache hits.
shenyu-plugin/shenyu-plugin-base/src/test/java/org/apache/shenyu/plugin/base/AbstractShenyuPluginTest.java Adds coverage for selector/rule cache-hit short-circuit behavior.
.gitignore Ignores .worktrees/ directory used for local worktrees.

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

if (Objects.isNull(selectorData)) {
return handleSelectorIfNull(pluginName, exchange, chain);
if (Objects.nonNull(selectorData)) {
if (StringUtils.isBlank(selectorData.getId())) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

merge the condition

@Aias00 Aias00 closed this Apr 2, 2026
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.

3 participants