swiftlang / swiftlang/swift-experimental-string-processing
Large regression in word boundary regexes
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 308
- Forks
- 52
- Avg merge
- 12h 45m
- Merged PRs (30d)
- 2
Description
I was running the benchmarker for this regex #"<(\w*)\b[^>]*>(.*?)<\/\1>"# which uses \b to match the end of a html tag and noticed it was running really slow
ed842cbb844a670314f22b37936b654748fad91d
Running
- htmlAll 11.8ms
main
Running
- htmlAll 3.08s
Some amount of regression was expected with the implementation of the new word breaking algorithm but a 300x slowdown seems unacceptable. A quick profile shows that ~99% of the time is spent in AssertFunction, with 90% of that being String._wordIndex(after:) and 10% being Set.insert
cc @Azoy @milseman
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the benchmarker and the reported HTML-tag regex, comparing the 11.8ms and 3.08s runs. Profile the word-boundary path, especially AssertFunction, String._wordIndex(after:) and Set.insert; done means substantially reducing the regression while preserving the regex result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100