**fix(runtime): simplify scanner buffer allocation in executor implementations**

This commit is contained in:
Luis Pater
2025-11-18 10:59:49 +08:00
parent 1c815c58a6
commit db2d22c978
8 changed files with 9 additions and 18 deletions

View File

@@ -219,8 +219,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A
// If from == to (Claude → Claude), directly forward the SSE stream without translation // If from == to (Claude → Claude), directly forward the SSE stream without translation
if from == to { if from == to {
scanner := bufio.NewScanner(decodedBody) scanner := bufio.NewScanner(decodedBody)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()
appendAPIResponseChunk(ctx, e.cfg, line) appendAPIResponseChunk(ctx, e.cfg, line)
@@ -243,8 +242,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A
// For other formats, use translation // For other formats, use translation
scanner := bufio.NewScanner(decodedBody) scanner := bufio.NewScanner(decodedBody)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -205,8 +205,7 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au
} }
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -319,8 +319,7 @@ func (e *GeminiCLIExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut
}() }()
if opts.Alt == "" { if opts.Alt == "" {
scanner := bufio.NewScanner(resp.Body) scanner := bufio.NewScanner(resp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -251,8 +251,7 @@ func (e *GeminiExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A
} }
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -240,8 +240,7 @@ func (e *GeminiVertexExecutor) ExecuteStream(ctx context.Context, auth *cliproxy
} }
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -199,8 +199,7 @@ func (e *IFlowExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -205,8 +205,7 @@ func (e *OpenAICompatExecutor) ExecuteStream(ctx context.Context, auth *cliproxy
} }
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()

View File

@@ -181,8 +181,7 @@ func (e *QwenExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Aut
} }
}() }()
scanner := bufio.NewScanner(httpResp.Body) scanner := bufio.NewScanner(httpResp.Body)
buf := make([]byte, 20_971_520) scanner.Buffer(nil, 20_971_520)
scanner.Buffer(buf, 20_971_520)
var param any var param any
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()