• yangjianbo's avatar
    perf(service): 优化 model 替换函数,用 gjson/sjson 替代全量 JSON 序列化 · 8226a4ce
    yangjianbo authored
    
    
    SSE 热路径中 replaceModelInSSELine 和 replaceModelInResponseBody 原来
    使用 json.Unmarshal/Marshal 对每个事件做全量反序列化再序列化,现改为
    gjson.Get/sjson.Set 精确字段操作,消除 O(n) 中间 map 分配,保持 JSON
    字段顺序不变。涉及 OpenAIGatewayService 和 GatewayService 两个服务。
    
    新增 23 个单元测试覆盖:顶层/嵌套 model 替换、不匹配跳过、空行/[DONE]/
    非法 JSON 等边界情况。
    
    Fixes: P1-08
    Co-Authored-By: default avatarClaude Opus 4.6 <noreply@anthropic.com>
    8226a4ce
openai_gateway_service_test.go 41.9 KB