Refactor dstep and enable benchmark#25
Open
ninioArtillero wants to merge 4 commits into
Open
Conversation
Co-authored-by: Facundo Domínguez <facundominguez@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a refactor that changes
dstepto use a single list traversal. Testing the change with (the now enabled)cabal benchI observed a ~1ms (10 %) improvement locally on average. In my opinion, this refactor improves the conciseness and clarity of this code. The test suite (cabal test) passes without casualties.Note this introduces no API or behavior changes.
The existing
bench/bench.hsfile was added to abenchmarkcomponent and tweaked just to succesfully compile and run withcabal bench. This files contains a single benchmark running the base diff algorithm (getDiff) on two 1,000 randomBools lists.The change
Previously, the local
nextDLstraversed the list producing two new nodes for each element, one produced by a horizontal step (dl) and the other by a vertical step (dl').Now,
nextDLshas been replaced by two helpers that locally expose those inner operations:hStepandvStep.Previously, the detailed behavior of
selectBestDLFromPairswas not evident; it depended on the specific arrangement of elements passed to itnextDLs.Now, with the new
stepAndMergedefinition it is easier to track how the precondition offurthestReachingis fulfilled: matching k-diagonal candidates are produced from successive input nodes and merged at each recursive call:Finally, the main body of the function is a bit more explicit about how the new wave front is constructed
Note that now the empty list case is explicitly addressed; previously this case was implicitly neglected by the pattern match