Skip to content

Avoid repeated prefix copies when checking quote escapes - #24

Open
akshitkhokhani wants to merge 1 commit into
promplate:mainfrom
akshitkhokhani:codex/partial-json-validation
Open

akshitkhokhani wants to merge 1 commit into
promplate:mainfrom
akshitkhokhani:codex/partial-json-validation

Conversation

@akshitkhokhani

Copy link
Copy Markdown

fix_fast copies the entire preceding input whenever it checks whether a quote is escaped. Arrays containing many short strings therefore accumulate quadratic slice volume, including incomplete arrays received while streaming.

Count only the adjacent backslashes before the quote instead. This preserves odd/even escape parity and avoids those repeated prefix copies.

Tests cover a deterministic slice-volume budget through loads, complete and partial arrays, and every prefix of escaped string/key examples across all allowance flags. The new cases fail 6 tests on the original code (18 correctness controls pass).

Validation: all 38 tests pass locally on Python 3.10 and 3.13. Tests use synthetic inputs with network access disabled. No claim is made about the complexity of the entire parser.

Developed with AI assistance and reviewed independently by a separate AI agent before submission.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b75b28e2-9b4e-4719-9b18-3d4c182069be
Commits

Reviewing files that changed from the base of the PR and between e0aa5e2 and ce16af4.

Files selected for processing: 2
  • src/partial_json_parser/core/myelin.py
  • tests/test_examples.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Summary

fix_fast now counts consecutive backslashes before a quote to determine escape parity, instead of copying the preceding input.

New tests measure slice work when loading complete and partial arrays. They also compare fix_fast with fix for every prefix of escaped list and dictionary inputs across all allowance flags.

Test results are not independently verified.

is_escaped now counts consecutive backslashes by scanning backward from the quote index. Tests measure slice-result lengths when loading complete and partial arrays. Additional tests compare fix_fast with fix across input prefixes containing varying backslash runs.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: Minimal · up to ce16a

The optimization preserves parser behavior and is ready to merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "Avoid repeated prefix copies when checking quote escapes" matches the main change: fix_fast now counts adjacent backslashes backward from the quote instead of copying the preceding input. I…
Description check Passed The description explains that fix_fast copies the preceding input on each quote-escape check, and that the fix counts only adjacent backslashes. It also describes the added tests (slice-volume budget,…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Avoid repeated prefix copies when checking quote escapes" matches the main change: fix_fast now counts adjacent backslashes backward from the quote instead of copying the preceding input. It is specific and concise, and a teammate scanning history would understand the primary change.

Full details: Description check

Explanation

The description explains that fix_fast copies the preceding input on each quote-escape check, and that the fix counts only adjacent backslashes. It also describes the added tests (slice-volume budget, complete and partial arrays, escaped string/key prefixes) and the validation run. This is directly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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