Permalink
Browse files

.

  • Loading branch information...
lihaoyi committed Dec 29, 2018
1 parent cc6519e commit beed8eb5420e80cfd74c2d0948b8ff1fedbff536
Showing with 11 additions and 4 deletions.
  1. +11 −4 post/35 - Compact, Streaming Pretty-Printing of Hierarchical Data.md
@@ -664,10 +664,17 @@ whole output in memory could easily take a long time.

The key insight behind this `prettyprint` algorithm is that for this common kind
of indentation-based mixed horizontal/vertical layout, you can make layout
decisions in a streaming fashion with only a bounded amount of buffering. This
gives the pretty-printer very predictable runtime characteristics, and allows it
to be used in a streaming fashion on very large data structures without
accumulating a corresponding very-large-string in memory.
decisions in a streaming fashion with only a bounded amount of buffering:

- When you need buffer *all* of a child's chunks, it is to verify that a child
can fit on one line, and thus buffering everything is cheap.

- When a child's output is very large, we can make that determination after
buffering at most one line of chunks, so that is cheap as well.

This gives the pretty-printer very predictable runtime characteristics, and
allows it to be used in a streaming fashion on very large data structures
without accumulating a corresponding very-large-string in memory.

The described `prettyprint` algorithm is currently being used in my Scala
[PPrint](http://www.lihaoyi.com/PPrint/) library, though extended in a few

0 comments on commit beed8eb

Please sign in to comment.