apache / apache/shenyu

[BUG] — `AiTokenLimiterPlugin`: `chunk.split("\\r?\\n")` (3-char regex, no fast path) per SSE chunk

Open Beginner friendly
#6,801 1 comment 0 reactions 0 assignees View on GitHub
feature: plugin priority: medium type: performance
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: Medium
- files: `shenyu-plugin-ai/shenyu-plugin-ai-token-limiter/.../AiTokenLimiterPlugin.java:268` (inside `appendResponse`'s `doOnNext`, per data buffer chunk of a streaming response)
- description: `String.split("\\r?\\n")` runs `Pattern.compile` per chunk; SSE streams emit many chunks per response. (Sibling `COMPLETION_TOKENS_PATTERN` at `:79` and `MAPPER` at `:196` are correctly precompiled.)
- impact: Per-chunk regex compilation on streaming AI responses.
- suggested_fix: Precompile `private static final Pattern SSE_LINE = Pattern.compile("\\r?\\n");`.
- confidence: High

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Read shenyu-plugin-ai/shenyu-plugin-ai-token-limiter/.../AiTokenLimiterPlugin.java, starting at appendResponse and line 268 in the doOnNext handler. Compare the existing precompiled COMPLETION_TOKENS_PATTERN and MAPPER fields, then verify that SSE chunks no longer trigger regex compilation per chunk.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
performance
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.