TH: support raw bytes literals
GHC represents String literals as ByteString internally for efficiency reasons. However, until now it wasn't possible to efficiently create large string literals with TH (e.g. to embed a file in a binary, cf #14741 (closed)): TH code had to unpack the bytes into a [Word8] that GHC then had to re-pack into a ByteString.
This patch adds the possibility to efficiently create a "string" literal from raw bytes. We get the following compile times for different sizes of TH created literals:
Size | Before | After | Gain |
---|---|---|---|
30K | 2.307s | 2.299 | 0% |
3M | 3.073s | 2.400s | 21% |
30M | 8.517s | 3.390s | 60% |
(where "Before" includes patches for #16198 (closed) and #16190 (closed) which are independent optimizations)
Ticket #14741 (closed) can be fixed if the original code uses the new TH facilities.