-
Notifications
You must be signed in to change notification settings - Fork 49
Reuse the executor in firstMatch #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
next step: reuse registers
Looking at Before
After
|
@@ -32,7 +32,7 @@ struct Processor< | |||
typealias Element = Input.Element | |||
|
|||
let input: Input | |||
let bounds: Range<Position> | |||
var bounds: Range<Position> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a bug or series of bugs that @natecook1000 is working on, but we probably won't want to be changing the bounds here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we're fine with leaving the lower bound at the beginning of the string? I guess it still makes sense as the bounds of the string and we just need to set currentPosition
to be where we want to start from when we reset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, though it might temporarily break some firstMatch
tests until some anchors get fixed. @natecook1000 can you work with Lily here?
for idx in xs.indices { | ||
xs[idx] = v | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or as an extension on MutableCollection
. @natecook1000 does such an algorithm exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try these out here before adding them to swift-algorithms:
extension MutableCollection {
mutating func setAll(to element: Element) {
self.withEach { $0 = element }
}
mutating func withEach(_ body: (inout Element) throws -> Void) rethrows {
var i = startIndex
while i < endIndex {
try body(&self[i])
formIndex(after: &i)
}
}
}
// usage:
self.bools.setAll(to: false)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also considering an underscore them so that no one accidentally ships it 😅
input, | ||
&cpu, | ||
startingFrom: low |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input, | |
&cpu, | |
startingFrom: low | |
input, &cpu, startingFrom: low |
The memmoves come from having to re-grow the save point stack, etc. Have you tried measuring now that we don't make new arrays? |
Reset the processor and it's registers instead of recreating them from scratch each iteration in
firstMatch
Using this benchmark https://github.com/rctcwyvrn/swift-experimental-string-processing/blob/lily-benchmarker/Sources/RegexBenchmark/Suite/FirstMatch.swift we get a pretty big speedup, 60ms to 10ms on my machine
There isn't much benefit in the original test case from #483 (BasicBacktrack in the suite) but maybe it'll be more pronounced once the other patch mentioned in that issue is implemented. There is also some slowdown in the other benchmarks and I'm not sure why. Since
wholeMatch
calls into_firstMatch
we also see some speedup in the css benchmarkBefore
After