Skip to content

perf(json): keep array scan linear on malformed output#136

Merged
Yif-Yang merged 1 commit into
microsoft:mainfrom
Yif-Yang:fix/json-array-scan-linear
Jul 14, 2026
Merged

perf(json): keep array scan linear on malformed output#136
Yif-Yang merged 1 commit into
microsoft:mainfrom
Yif-Yang:fix/json-array-scan-linear

Conversation

@Yif-Yang

Copy link
Copy Markdown
Contributor

Summary

Immediate maintainer follow-up to #103, which was merged first with the contributor commits and attribution intact.

The unmatched-brace recovery added by #103 is functionally correct, but it looked ahead to EOF for every unmatched {, making malformed brace-heavy model output quadratic. This change:

  • precomputes balanced object endpoints in one string/escape-aware stack pass;
  • preserves the behavior where an unmatched prose brace does not hide a later valid array;
  • continues to skip arrays nested inside balanced objects; and
  • adds a deterministic character-access regression test rather than a timing-based assertion.

Validation

  • pytest tests/test_json_utils.py -q: 40 passed, 3 skipped
  • pytest tests/ -q: 276 passed, 6 skipped
  • 10,000 unmatched braces: approximately 4.8 s → 0.002 s
  • 100,000 unmatched braces: approximately 0.022 s
  • git diff --check: clean
  • Claude Code / Opus 4.8 read-only review: no blockers, MERGE

@Yif-Yang
Yif-Yang merged commit 42270f7 into microsoft:main Jul 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant