Skip to content

perf(runtime): advance fuzzy Edit line offsets incrementally - #6050

Merged
Astro-Han merged 1 commit into
apache:mainfrom
seekskyworld:perf/linear-fuzzy-edit-offsets
Oct 11, 2026
Merged

Astro-Han merged 1 commit into
apache:mainfrom
seekskyworld:perf/linear-fuzzy-edit-offsets

Conversation

@seekskyworld

@seekskyworld seekskyworld commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Edit's line-trimmed fallback rescans every preceding line to locate each matching candidate. Track the source offset once as lines advance, preserving candidate selection, ambiguity errors, newline handling and line ranges. On an admitted 49,000-line repetitive fixture, median helper latency falls from 653.52ms to 4.48ms (10 samples per version; method and reproduction in the issue).

Fixes #6049

Verification

  • 64 Edit / filesystem-worker / tool-entry tests pass; the 22 Edit tests also pass on Node 22.19.0.
  • The new CPU-budget regression fails on the old implementation (2.69 CPU seconds for four edits) and passes with this change. 18,000 seeded before/after cases produce identical results or errors.
  • Repository build, typecheck, lint, format, Desktop/UI knip, ASF headers and diff checks pass.
  • Full Runtime was not entirely green: each of two runs had 3,830 pass / 14 skip / 1 failure, in different unchanged process-lifecycle fixtures (owned-child-process descendant cleanup, then shell-owner-death reading incomplete fixture JSON). The first failing case passes in isolation and its unchanged baseline suite passes 12/12. The second failing file passes 6/6 when rerun alone. These failures are retained in the validation record; no unrelated test was weakened.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex investigated, implemented and tested this change at @seekskyworld's direction. Final review and merge remain human decisions.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Avoid rescanning every prior line for each line-trimmed candidate.
Keep ambiguity, newline, size-limit and replacement semantics unchanged.
Add offset coverage and a CPU-budget regression for repetitive inputs.

Fixes apache#6049

Generated-by: OpenAI Codex
Signed-off-by: seekskyworld <djh1813553759@gmail.com>
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Oct 10, 2026

@Astro-Han Astro-Han 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

I found no actionable P0–P3 issue at a762ca51f269eb4f83eede95615ec7f414a6fc7b.

The change in packages/runtime/src/edit-replace.ts:229 maintains the next line's UTF-16 offset while scanning, rather than summing the entire preceding prefix for each candidate. Advancing that offset before rejecting a nonmatch preserves the original locations; CRLF, unequal line lengths, surrogate pairs, EOF handling, uniqueness checks, fuzzy limits, and literal replacement remain unchanged. The helper is used by both the filesystem executor and worker.

Validation: 46 Edit/filesystem-worker tests passed. An independent seeded comparison of 25,000 inputs produced identical full results or errors on the parent and this head. On the 49,000 repeated-line case, five-call median helper time fell from 9,798.71 ms to 26.51 ms in this environment; four calls consumed 30,862.07 ms versus 80.76 ms of process CPU. The parent's result exceeds the added one-second CPU guard, while this head remains below it. These are helper measurements, not end-to-end latency guarantees.

No protocol epoch, API, dependency, or persistence change. GitHub reports this head mergeable, with successful CI and Windows packaging checks. I did not run Windows locally or repeat the entire repository test suite.

@Astro-Han Astro-Han 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.

Approved at @Astro-Han's explicit request: the automated review of this exact head found no blocking (P0–P2) issues, and CI is green.

@Astro-Han
Astro-Han merged commit 38b51cc into apache:main Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(runtime): avoid quadratic prefix rescans in fuzzy Edit matching

2 participants