AlinsRan opened a new pull request, #13391:
URL: https://github.com/apache/apisix/pull/13391

   ## Summary
   
   ### 1. Remove PCRE dependency from SSE decoder
   
   Replace `ngx_re.split` (PCRE) in `sse.decode()` with a pure Lua forward scan 
(`string.find`).
   
   **Benefit:** Eliminates regex compilation overhead on each streaming chunk. 
PCRE calls are expensive because they allocate JIT memory; replacing them with 
`string.find` reduces per-chunk CPU cost and memory allocations in 
high-throughput SSE streams.
   
   ### 2. Add `decode_buf(buf)` - single-pass buffer decoding
   
   New function that combines `split_buf` + `decode` into one O(n) forward 
pass, returning `(events, remainder)`.
   
   **Benefit:** The current hot path calls `split_buf` then `decode`, scanning 
the buffer twice. `decode_buf` does both in one pass, halving scan work per 
chunk. Callers that only need the combined result can use this directly.
   
   ### 3. Fix SSE comment lines being treated as fields
   
   SSE lines starting with `:` are comment lines per the [SSE 
spec](https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream).
 The previous `decode()` used a regex that skipped lines without a named field 
but the new implementation correctly identifies `colon == 1` as a comment and 
skips it without setting `has_field = true`, which previously caused 
comment-only blocks to be emitted as empty events.
   
   **Benefit:** Correct spec compliance. Some providers (e.g., keep-alive pings 
sent as `: keep-alive`) would produce spurious empty events before this fix.
   
   ## Test
   
   Added TEST 29 in `t/plugin/ai-proxy-protocol-conversion.t`: SSE comment 
lines interleaved with real events are correctly discarded by `decode_buf`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to