mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1562] [CLOSED] serve: compact streamed line fragments into blocks #3533
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3533
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1562
Author: @InB4DevOps
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:perf/parser-line-blocks📝 Commits (1)
a811f60serve: compact streamed line fragments into blocks📊 Changes
2 files changed (+160 additions, -2 deletions)
View changed files
📝
serve/frontend.py(+34 -2)➕
serve/test_parser_track.py(+126 -0)📄 Description
Summary
Avoid copying the entire growing current line for each streamed text fragment in
OutputParser._track().lineproperty, including snapshot restoration and fence/inline-code decisions.This change is independent of #1542 and #1557. The branch contains only line tracking/storage and its tests. Partial-tag matching, tool-body closing-tag scans, GPU/native code and profiling infrastructure are unchanged.
Standalone validation
Both the untouched baseline and isolated candidate started at upstream
fb58e0dbc8399662c0e47c76578c6e878b14f6cf. The candidate contained no other local optimizations.Coverage includes per-fragment line/fence/backtick state, Unicode, CRLF, varied initial states, long lines, quoted tool markers, recovery, streamed tools, compaction boundaries, materialization followed by appends, and snapshot restoration. The reference parser overrides the new property with the old string attribute as well as retaining the old
_track()implementation.git diff --checkpassed.Windows correctness and performance validation: pending.
Measurements and tradeoffs
Intel Core i7-12700KF, 20 logical CPUs; Linux 7.0.0-38-generic, glibc 2.39, CPython 3.12.3, Jinja2 3.1.6. Default scheduling/power policy, no affinity pinning. Seven fresh-process samples per checkout, alternating baseline/candidate order, two warmups per case, fixed 16-character chunks. Fixture construction and validation were outside timing. No model, GPU, or profiling timers were involved.
Median elapsed ms, untouched upstream → PR:
The 512 KiB unbroken line used 87.1% less elapsed time (candidate range 41.56–43.59 ms, baseline 322.00–332.07 ms). Candidate time grew about 3.9× for 4× the line length in this workload. These are synthetic parser CPU results, not end-to-end inference speedups.
Tradeoff: ordinary multiline medians were 2–3% slower, and the deliberately newline-heavy case was about 7% slower. The table retains those regressions. Frequent explicit line inspections can still force repeated joins; this does not claim linear scaling for every parser input or fix tool-body accumulation.
All 112 measured outputs matched fixture content/final arguments/streamed JSON and had matching hashes across both checkouts and samples. Random tool IDs were excluded.
Memory
A separate untimed
tracemallocrun fed 32,768 distinct generated 16-character fragments (512 KiB) and discarded emitted events:linelineCompaction keeps retained memory near the original representation while avoiding per-fragment whole-line copies. This measures Python allocations, not RSS; total stored text still grows with line length.
Minimal reproduction
With Jinja2 installed, run the following from each checkout root. It reproduces one 512 KiB long-line timing sample after two warmups, followed by a separate memory check. Repeat timing in fresh processes and alternate checkout order. Set
scale = 4for the smaller timing case.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.