Skip to content
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

BestFirstSearch: only update best at the end #4236

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ private class BestFirstSearch private (range: Set[Range])(implicit
var optimalNotFound = true
actualSplit.foreach { split =>
val nextState = curr.next(split, allAltAreNL)
val updateBest = !keepSlowStates && depth == 0 && split.isNL &&
best.getOrElseUpdate(curr.depth, nextState).eq(nextState)
style.runner.event(FormatEvent.Enqueue(split))
split.optimalAt match {
val stateToQueue = split.optimalAt match {
case Some(OptimalToken(token, killOnFail))
if acceptOptimalAtHints && optimalNotFound &&
actualSplit.lengthCompare(1) > 0 && depth < maxDepth &&
Expand All @@ -173,20 +171,21 @@ private class BestFirstSearch private (range: Set[Range])(implicit
if (null != furtherState) {
val overflow = furtherState.appliedPenalty >
nextNextState.appliedPenalty
if (overflow) enqueue(nextNextState)
if (overflow) nextNextState
else {
optimalNotFound = false
enqueue(furtherState)
furtherState
}
} else if (!killOnFail && nextState.split.cost <= maxCost)
// TODO(olafur) DRY. This solution can still be optimal.
enqueue(nextState)
else // else kill branch
if (updateBest) best.remove(curr.depth)
} else if (!killOnFail) nextState
else null // else kill branch
case _ if optimalNotFound && nextState.split.cost <= maxCost =>
enqueue(nextState)
case _ => // Kill branch.
if (updateBest) best.remove(curr.depth)
nextState
case _ => null // Kill branch.
}
if (null ne stateToQueue) {
if (!keepSlowStates && depth == 0 && split.isNL) best
.getOrElseUpdate(curr.depth, nextState)
enqueue(stateToQueue)
}
}
}
Expand Down
Loading