Repository navigation
tool_parse: a GLM call's keys without values read in linear time - #883
Conversation
glmCall walked the later </arg_key> tags again for every <arg_key>. valueKey finds the first </arg_key> an <arg_value> follows, and glmCall keeps it, and the first </arg_value> after it, until it has read past them.
|
Thank you, @jishnuvenugopal, for covering the key-only GLM call and its unchanged empty-object result. At 904e2bd, This is ready for parser integration checks alongside #881 and #882. The three heads are siblings, so the landing batch needs all three changes applied together. Posted by Ash's AI Assistant Synthena |
… against the old search #881's putBack is exact only for replacements without a NUL, which json.quote guarantees for its one caller; its doc line now says so, and the sort line says the cost: one pass over the text, then M log M for M marks. The two timing tests from #882 and #883 now name what they measure (each opener, and each key and value end, searched once) instead of claiming that all tool parsing is linear. A new test parses 20,000 random GLM calls (keys without values, values without closers, repeated keys, stray tags, whitespace) and checks each against the same pairs found by #883's parent loop, written out plainly: the arguments must be identical.
…VIEW names the refused GLM pair requests rightly One line each for #881, #882, #883, #889, #890, #709, #848, #892, #867, #868, #871 and #873, crediting their authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0 (backend.zig and engine.zig both test temperature > 0).
|
Thank you, @jishnuvenugopal, for eliminating repeated key-end and value-end searches in GLM calls. #883 is included in 1.0.12 as merge 801aa0f, at 904e2bd. Our 084406f adds a 20,000-case comparison against the parent's loop, covering missing values and closers, repeated keys, stray tags and whitespace. The arguments must match byte for byte. The timing test also names the operation it measures. The comparison passes inside the full suites: macOS has 2,968 of 2,978 tests passing with 10 skipped, and Linux 1,368 of 1,375 with 7 skipped. Posted by Ash's AI Assistant Synthena |
The argument regex's lazy key retried every later </arg_key> from every <arg_key>, so a call whose keys have no values took 6.1 s for findall and 6.7 s for sub at 8,000 keys (191k characters); the parser runs both. A forward-only scan returns the same pairs and leftover text: equal to the regex on 20,000 random calls. Ports upstream ashhart#883. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… against the old search ashhart#881's putBack is exact only for replacements without a NUL, which json.quote guarantees for its one caller; its doc line now says so, and the sort line says the cost: one pass over the text, then M log M for M marks. The two timing tests from ashhart#882 and ashhart#883 now name what they measure (each opener, and each key and value end, searched once) instead of claiming that all tool parsing is linear. A new test parses 20,000 random GLM calls (keys without values, values without closers, repeated keys, stray tags, whitespace) and checks each against the same pairs found by ashhart#883's parent loop, written out plainly: the arguments must be identical.
…VIEW names the refused GLM pair requests rightly One line each for ashhart#881, ashhart#882, ashhart#883, ashhart#889, ashhart#890, ashhart#709, ashhart#848, ashhart#892, ashhart#867, ashhart#868, ashhart#871 and ashhart#873, crediting their authors. ZIG-PREVIEW said a two-Mac GLM pair refuses "temperature-1" requests; it refuses any temperature above 0 (backend.zig and engine.zig both test temperature > 0).
What this changes
glmCall(zig/src/server/tool_parse.zig) pairs each<arg_key>with the first</arg_key>that an<arg_value>follows, and walked the later
</arg_key>tags again for every<arg_key>.valueKeyfinds that</arg_key>, andglmCallkeeps it, and the first</arg_value>after it, until it has read past them. The keys only move forward,so the pairs are the same.
Verified outcome
read at 128 KiB, whether the call was closed or the reply's end left it open.
for every key.
byte-identical results.
Receipt
Environment:
mainat c7137bb, Zig 0.17.0, Apple M4, macOS 27.0.1. Host code: no model or GPU.Exactness: n/a. No engine change; the reply's tokens and text are the same.
Decode speed before and after: n/a.
bench_openai.py's prompts offer no tools, and only replies to requests thatoffer tools are parsed.
Prompt speed before and after: n/a, for the same reason.
Speed on
<tool_call>lookupthen<arg_key>n</arg_key>repeated, in ReleaseSafe as the server ships, fastest ofthree, c7137bb then this branch:
parse,</tool_call>after the keyscloseCall, the call left openSame output: a local fuzz harness (not part of this change) ran 50,000 edited replies through
parse,closeCall,hideToolCallsandfinishedProseon c7137bb and on this branch. A digest of everything they returned, call idsleft out, is equal (4c8dc88dffd56f19).
Tests run:
a GLM call's keys without values read in linear time(tool_parse_test.zig): one call with 800 keys andone with 6,400. 8x the keys may take at most 24x the time (or under 20 ms), the bound fuzz-cortheon's
linear-time test uses. It fails on c7137bb and passes on this branch.
zig build test test-golden -Dcpu=apple_m1, uncached: 164 of 164 steps, 1982 of 1990 tests pass, 8 skip,0 fail (c7137bb: 1981 of 1989, 8 skip); the one more is the new test.
zig build fuzz-cortheonpasses.zig fmt --check build.zig zigis clean. Lean: 527 problems on the base and 527 on this branch, 0 new(
lean_new.py).Not run, and why: no CUDA host here. The parser is server code that both backends use, and its tests need no GPU.
Checklist
change.)
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Noengine change; not re-run.)
arithmetic changes.)