NOSSLETTER.techLIVE
back to archive

[Perf][Parser] Skip per-tick conversion of non-JSON DeepSeek DSML argument values

Language: Python+124 -4performance
concepts demonstrated
String parsing and manipulationConditional logic optimizationPerformance optimization techniquesUnit testing for parser behavior
The Issue & Context

Before this change, DeepSeek parsers repeatedly reconverted large non-JSON markup string arguments on every chunk boundary during non-streaming parse calls, causing quadratic parsing time and blocking the API server event loop.

Root Cause Analysis

The parser treated non-JSON markup argument values as if they needed conversion on each '>' chunk, triggering repeated costly string reconversions inside DeepSeekV4Parser.parse(), especially for arguments lacking a string attribute or with string="false".

Solution Strategy & Architectural Pattern

The PR modifies the parser to hold the entire open markup value until its closing tag before converting, skipping per-tick reconversion for non-JSON markup argument values. This reduces the number of conversions from thousands to a handful, drastically cutting parse time without changing parsed results or affecting streaming behavior.

Key Takeaway for Contributors

When parsing large markup or text arguments, deferring conversion until the full value is available can avoid expensive repeated work caused by chunked input processing, improving performance without sacrificing correctness.