Repository navigation
Commit 825d90d
committed
perf(executor): stop re-parsing the whole structured output on every streamed token
When a chat selects a response-format field, StreamingResponseFormatProcessor
re-ran JSON.parse on the whole buffer for every token delta, then scanned it
twice more with brace-count regexes, so CPU per response grew with the square
of the output length. Text can only parse to an object once it ends in `}` or
`]`, so parse only then. The brace-count branch re-parsed the same
`buffer.trim()` that had just failed or yielded a non-object, so it could never
return a result and is removed.1 parent 0ea25f4 commit 825d90d
1 file changed
Lines changed: 7 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| |||
114 | 120 | | |
115 | 121 | | |
116 | 122 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 123 | | |
144 | 124 | | |
145 | 125 | | |
| |||
0 commit comments