Merge pull request #27747 from hashicorp/backport/alisdair/optimize-large-multi-line-string-outputs/precisely-feasible-glider

Backport of cli: Optimize for large multi-line string outputs into v0.14
pull/27789/head
Alisdair McDiarmid 5 years ago committed by GitHub
commit cde0b2451a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ ENHANCEMENTS:
BUG FIXES:
* cli: Fix `show -json` not outputting the full module tree when some child modules have no resources [GH-27352]
* cli: Fix excessively slow rendering of very large multi-line string outputs [GH-27746]
## 0.14.6 (February 04, 2021)

@ -904,23 +904,35 @@ func (p *blockBodyDiffPrinter) writeValueDiff(old, new cty.Value, indent int, pa
}
}
diffLines := ctySequenceDiff(oldLines, newLines)
for _, diffLine := range diffLines {
p.buf.WriteString(strings.Repeat(" ", indent+2))
p.writeActionSymbol(diffLine.Action)
switch diffLine.Action {
case plans.NoOp, plans.Delete:
p.buf.WriteString(diffLine.Before.AsString())
case plans.Create:
p.buf.WriteString(diffLine.After.AsString())
default:
// Should never happen since the above covers all
// actions that ctySequenceDiff can return for strings
p.buf.WriteString(diffLine.After.AsString())
// Optimization for strings which are exactly equal: just print
// directly without calculating the sequence diff. This makes a
// significant difference when this code path is reached via a
// writeValue call with a large multi-line string.
if oldS == newS {
for _, line := range newLines {
p.buf.WriteString(strings.Repeat(" ", indent+4))
p.buf.WriteString(line.AsString())
p.buf.WriteString("\n")
}
} else {
diffLines := ctySequenceDiff(oldLines, newLines)
for _, diffLine := range diffLines {
p.buf.WriteString(strings.Repeat(" ", indent+2))
p.writeActionSymbol(diffLine.Action)
switch diffLine.Action {
case plans.NoOp, plans.Delete:
p.buf.WriteString(diffLine.Before.AsString())
case plans.Create:
p.buf.WriteString(diffLine.After.AsString())
default:
// Should never happen since the above covers all
// actions that ctySequenceDiff can return for strings
p.buf.WriteString(diffLine.After.AsString())
}
p.buf.WriteString("\n")
}
p.buf.WriteString("\n")
}
p.buf.WriteString(strings.Repeat(" ", indent)) // +4 here because there's no symbol

Loading…
Cancel
Save