Skip to content

Make StringExtractor.extractStrings linear - #25

Merged
rickhohler merged 1 commit into
mainfrom
perf/linear-string-extraction
Oct 30, 2026
Merged

rickhohler merged 1 commit into
mainfrom
perf/linear-string-extraction

Conversation

@rickhohler

Copy link
Copy Markdown
Collaborator

extractStrings appended a Character at a time and checked current.count (linear in the run) before every byte, so long printable runs cost up to maxLength× their length. It now gathers bytes and builds each string once.

Results are unchanged: a new test compares against the previous implementation on 200 random inputs (text, whitespace, CR LF pairs, Latin-1) at four length settings, including minLength: 0. The existing StringExtractor tests moved to Algorithms/Text/StringExtractorTests.swift.

Found profiling disk image imports, where string scans of whole disks dominated.

Tests: 391 + 32, 0 failures.

🤖 Generated with Claude Code

Runs were built a Character at a time with String.count (linear) checked
before every byte. Gather bytes and build each string once; results are
unchanged (equivalence test against the old implementation on random
data, including CR LF pairs and minLength 0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rickhohler
rickhohler merged commit 956e601 into main Oct 30, 2026
1 check passed
@rickhohler
rickhohler deleted the perf/linear-string-extraction branch October 30, 2026 01:31
@rickhohler rickhohler mentioned this pull request Oct 30, 2026
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