Skip to content

Avoid rescanning in FormPipeReader when form data arrives incrementally - #10219

Merged
wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-eec8e89-main
Oct 14, 2026
Merged

wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-eec8e89-main

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Oct 14, 2026

Copy link
Copy Markdown
Member

Avoids rescanning full body data from pipeReader on any new incoming data.

…en form data arrives incrementally

Avoids rescanning full body data from pipeReader on any new incoming data

----
#### AI description  (iteration 1)
#### PR Classification
Performance optimization bug fix to eliminate redundant rescanning of form data bytes when data arrives incrementally in FormPipeReader.

#### PR Summary
This PR fixes a performance issue in FormPipeReader where already-scanned bytes were being rescanned on each incremental read, causing O(n²) behavior. The fix introduces a `scannedLength` parameter to track scanning progress and resume from the correct position.

- `FormPipeReader.cs`: Added `scannedLength` parameter to `ParseFormValues`, `ParseFormValuesFast`, and `ParseValuesSlow` methods to track and skip already-scanned bytes, ensuring each byte is scanned at most once plus potential delimiter overlap
- `FormPipeReaderTests.cs`: Added comprehensive tests verifying that incremental reads (single-byte and multi-segment) scan each byte only once, and that resumed scans correctly parse whole key-value pairs while still enforcing length limits
- `FormPipeReader.cs`: Handles edge cases for multi-byte delimiters (UTF-16/UTF-32) by accounting for delimiter overlap at read boundaries to prevent missing delimiters split across reads
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Co-authored-by: Copilot <[email protected]>
@wtgodbe
wtgodbe requested review from DeagleGross and a balanced review from Copilot October 14, 2026 16:10
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team October 14, 2026 16:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

🟢 Approval recommended

The implementation consistently preserves parsing behavior while avoiding redundant delimiter scans, with comprehensive targeted coverage.

0 open findings

What changed in this PR

Optimizes incremental form parsing by tracking already-scanned bytes and resuming delimiter searches.

Changes:

  • Adds scan-position tracking to fast and multi-segment parsing paths.
  • Adds incremental-read and multi-byte delimiter tests.
  • Updates microbenchmarks for the new parser signature.
File Description
FormPipeReader.cs Resumes parsing from the previous scan position.
FormPipeReaderTests.cs Tests incremental reads, limits, and delimiter boundaries.
FormPipeReaderInternalsBenchmark.cs Updates benchmark parser calls.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@wtgodbe
wtgodbe merged commit c820fc3 into main Oct 14, 2026
12 checks passed
@wtgodbe
wtgodbe deleted the wtgodbe/port-eec8e89-main branch October 14, 2026 20:57
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.

3 participants