3 ms·
> that is, if there are two "paths" of breaking that eventually end with the same break at the same indentations (plural because of the matching-siblings issue
by munificent 7y ago
> that is, if there are two "paths" of breaking that eventually end with the same break at the same indentations (plural because of the matching-siblings issue), then you should have to recalculate the rest only once?
In theory, yes. But there are other constraints across a statement that the formatter tries to preserve, so the memoization needs to take those into account too. Basically, the key used in the memo table is more complex than just "where in the code" and "indentation level". It has to roll in some extra contextual information about other line breaking choices that were made if those choices force this subtree to be formatted in certain ways.
> Couldn't there be cases where avoiding the "best" split in the first step could ultimately result in a lower overall cost?
Yes, there exactly are, which is why it does indeed find the overall lowest cost solution.