Skip to content

Keep code detection fast on a mail that is one long line - #22

Merged
ugzv merged 1 commit into
mainfrom
fix/detection-long-line
Nov 10, 2026
Merged

ugzv merged 1 commit into
mainfrom
fix/detection-long-line

Conversation

@ugzv

@ugzv ugzv commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Summary

Follows #21. A mail whose text is one very long line with thousands of code candidates still froze detection: every candidate read its whole line, so a 250 KB mail took close to a minute on the main thread.

The line around a candidate is now read at most 1,000 UTF-16 units each way. Lines shorter than that are read exactly as before; on a longer one, the checks that look at "the code's line" see that window.

Privacy and safety

No change to what CodeCatch reads, stores, copies, types, opens or sends.

Tests

longMailCannotStallDetection now also runs the one-line mail; it fails on the old code. It compares the CPU cost of a short and a long mail, so it does not depend on how fast the machine is. The full sample corpus in code-samples.txt still passes unchanged.

@ugzv
ugzv merged commit 79d753e into main Nov 10, 2026
3 checks passed
@ugzv
ugzv deleted the fix/detection-long-line branch November 10, 2026 09:49
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