Static Backend should use Lazy Text
From everything that I've ever learned ever in terms of text processing in haskell (specifically generating it), lazy text (or bytestrings) are preferrable for arbitrarily long strings. For "relatively" short strings, Data.Text
can be preferable, but for anything potentially large in memory (i.e., responses from a HTTP server), lazy text / bytestrings are preferred. This is why the low-level response mechanisms in WAI are only implemented for lazy data types.
This should be an easy fix - I wonder if we could cut-to-the-chase and just build lazy bytestrings from the get-go, and forget about text all together (literal strings in haskell are utf8 (or utf-16, I'm not 100%) for bytestring, via {-# LANGUAGE OverloadedStrings #-}
). If not, maybe a lazy text builder would be a good option. Either way, I think there's a (albeit fringe) potential performance gain here.
In summary, here are some options:
- use
Data.Text.Lazy
instead ofData.Text
for all static generation - use
Data.Text.Lazy.Builder
to packData.Text
values, then emit a singleData.Text.Lazy
during render - use text-utf8 instead to reduce memory (using
Data.Text.Lazy
and/orData.Text.Lazy.Builder
from that package as well), however I recommend staying with utf-16, as Windows relies on it.
I don't recommend using text-short, as it's intended for storing many strictly allocated strings (like a map of text values), rather than one long string as we're doing here.