[BUG] MetaDataCache.obtain does O(n) linear scan with AntPathMatcher on every cache miss
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
## Description
On a cache miss, `obtain` streams over **all** `META_DATA_MAP.values()`, calling `PathMatchUtils.match(data.getPath(), path)` (AntPathMatcher, which compiles a regex per call) for each, `findFirst()`. A single miss = O(M) AntPathMatcher invocations where M = number of registered metadata entries. Misses happen for every new/high-cardinality path and after any `clean(path)` invalidation.
## Location
```
shenyu-plugin-base/.../cache/MetaDataCache.java:122-138
```
## Impact
High-cardinality traffic x M regex compiles. For a gateway with 1000 metadata entries and high path cardinality, every new path costs 1000 regex compiles.
## Suggested fix
Index metadata by path prefix (trie) or precompile patterns keyed by metadata path.
## Related existing issue(s)
None
_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in shenyu-plugin-base/.../cache/MetaDataCache.java:122-138 and trace how obtain handles cache misses and how clean(path) invalidates entries. Compare the proposed prefix index or precompiled-pattern approaches, then verify that matching and invalidation remain correct while avoiding a scan of every metadata entry; the issue does not name a test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100