SIGN IN SIGN UP

input: Avoid rescanning long lines for diagnostic positions (#2712)

Closes #2710

## Description

Replace the linear character scan in `RopeExt::position_to_offset` with
Ropey's indexed character-to-byte conversion.

The previous implementation iterated from the beginning of a line for
each
diagnostic range endpoint. Applying many diagnostics near the end of a
long
line therefore took `O(number of diagnostics * line length)` work on the
synchronous update path.

This change enables Ropey's `metric_chars` feature and uses
`RopeSlice::char_to_byte_idx` to resolve the requested column. The
column is
clamped to `line.len_chars()` first, preserving the existing behavior
for
positions beyond the end of a line.

No marker limits, asynchronous processing, or unrelated position
semantics are
changed.

## Performance

The same release-mode reproduction used 1,000 diagnostics whose start
and end
positions were beyond the end of a 1,000,000-character ASCII line:

| | Before | After |
| --- | ---: | ---: |
| Elapsed time | 4,937.835 ms | 0.729 ms |
| Three-second deadline | Timed out (`124`) | Completed (`0`) |
| Stored diagnostics | 1,000 | 1,000 |

For comparison, after the change the same document and diagnostic count
with
column `1` took 0.667 ms. Large valid or out-of-range columns no longer
cause a
full line scan for each range endpoint.

## How to Test

Run the complete `gpui-base` library test suite:

```console
cargo test -p gpui-base --lib --locked
```

Result: 267 passed, 0 failed.

Check formatting and whitespace:

```console
cargo fmt --all -- --check
git diff --check
```

The existing Unicode position assertions continue to pass, and an
additional
assertion verifies that `u32::MAX` as a column still resolves to the end
of the
line.

## AI Assistance

Codex was used to analyze the performance issue, identify Ropey's
indexed
character metric API, implement the change, add the regression
assertion, and
draft this description. The resulting diff was reviewed by the
contributor and
validated with the tests listed above before submission.

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(if any) is accurate.
- [x] Passed `cargo test -p gpui-base --lib --locked`.
- [x] Passed `cargo fmt --all -- --check` and `git diff --check`.
- [x] Story testing is not applicable because this change does not
modify rendering or interaction behavior.
- [x] Cross-platform performance testing is not applicable because the
change uses platform-independent Ropey indexing.
L
luren committed
f3ba893bd6a996ab0699266ba774b5bbb7f0ca1c
Parent: 137cc94
Committed by GitHub <noreply@github.com> on 8/14/2026, 4:55:39 PM