The new implementation was benchmarked against the old It performs
similarly to the old on all input sizes, when building just the
fields. Performance should improve a bit when rendering whole
messages because the Builder will fuse into the larger message
builder; no intermediate ByteStrings or chunks will be allocated.
At first it surprised me that performance was so similar, even for
large inputs, given the large number of small strict ByteStrings
being appended. But on further consideration, 'unwords' and
'intercalate' are O(n). These are two separate "layers" in the
implementation but the overall complexity is O(n).
Refactor foldUnstructured and buildField to use a Builder instead of building an intermediate strict ByteString.
This is in anticipation of further changes to resolve https://github.com/purebred-mua/purebred-email/issues/56.
The new implementation was benchmarked against the old It performs similarly to the old on all input sizes, when building just the fields. Performance should improve a bit when rendering whole messages because the Builder will fuse into the larger message builder; no intermediate ByteStrings or chunks will be allocated.
At first it surprised me that performance was so similar, even for large inputs, given the large number of small strict ByteStrings being appended. But on further consideration, 'unwords' and 'intercalate' are O(n). These are two separate "layers" in the implementation but the overall complexity is O(n).