Skip to content

馃 perf: Match Tolerant Edit Lines Without Rebuilding Windows - #16562

Merged
danny-avila merged 1 commit into
devfrom
lia/linear-edit-matcher
Sep 30, 2026
Merged

danny-avila merged 1 commit into
devfrom
lia/linear-edit-matcher

Conversation

@lia-by-librechat

Copy link
Copy Markdown
Contributor

Pull Request

Summary

Large multiline edit_file misses in skill authoring or code-execution files synchronously rebuild, normalize, and join an overlapping line window at every candidate position. This can block the API event loop. The matcher was introduced in #13435 and remains in #16520.

Normalize trimmed lines once and match their integer IDs with KMP. Bound the final indentation fallback using the preceding strategies, without changing exact-match precedence, ambiguity detection, overlapping ranges, match limits, or offsets into the original UTF-16 content.

Related to #13435 and #16520.

How it works

exact
  line-trimmed: intern lines, build KMP prefix table, scan once
    whitespace-normalized: unchanged
      indentation-flexible: single nonblank anchor, reject ineligible windows in O(1)

After whitespace-normalized misses, an indentation match cannot contain two nonblank lines: such a match would already match at least two whitespace-separated tokens. All-blank matches are already handled by line-trimmed. For the remaining single-nonblank-line case, prefix counts reject windows containing other nonblank lines before comparing their suffixes. Each file line belongs to at most two eligible windows, preserving window-local indentation and residual whitespace without repeated normalization of overlapping windows.

Type of change

  • Bug fix
  • Performance improvement
  • Tests / tooling / CI

Testing

Tested environments/configuration: Node 24.16.0 in the attached Linux workspace. The original reported 18.6 seconds is not independently reproduced.

Automated tests:

  • Added handler-path regressions for strategy ordering, repeated prefixes, overlapping ambiguity/replace_all, UTF-16 and CRLF offsets, EOF, blank lines, window-local indentation, residual whitespace, and the existing match cap.
  • Added a deterministic work-count regression: 400,000-byte content and a 16,007-byte needle require exactly 20,802 trimEnd calls, once per file/needle line, rather than once per candidate window.
  • Source-level harness passed 15 behavioral fixtures and 50,000 seeded differential comparisons against origin/dev.
  • Single-run source-level benchmark on the same 400,000-byte file/16,007-byte needle: line-trimmed 393.71 ms before versus 2.09 ms after; indentation-flexible 798.82 ms before versus 2.85 ms after. These are fixture-specific local measurements, not a universal edit latency guarantee.
  • Full dependency installation failed because the workspace disk is nearly full. Focused handler Jest, API workspace typechecking, static checks, and Lighthouse verification status will be updated after available local checks and CI finish.

Screenshots / recordings

No user-facing UI change.

Risk / compatibility

No configuration, authorization, storage, or public API changes. The whitespace-normalized regular-expression strategy is unchanged. The optimized indentation path relies on remaining last in the existing strategy order.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary
  • Required dependency changes have been merged/published (N/A)
  • Required documentation PR: N/A

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Review head: 013ea2e00bbab3d7e110585d555524f3f8185d61. This head replaces overlapping-window normalization with KMP for trimmed lines and bounded single-anchor indentation fallback. It adds regressions for strategy precedence, ambiguity, overlapping replace_all ranges, original UTF-16/CRLF offsets, blank lines, EOF, local indentation, match limits, and linear normalization work. Source-level verification has passed 15 fixtures and 50,000 differential cases. CI and independent review are in progress.

@danny-avila
danny-avila merged commit cd63070 into dev Sep 30, 2026
28 checks passed
@danny-avila
danny-avila deleted the lia/linear-edit-matcher branch September 30, 2026 11:18
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.

2 participants