quchen / prettyprinter

A modern, extensible and well-documented prettyprinter.
BSD 2-Clause "Simplified" License
293 stars 34 forks source link

`unsafeTextWithoutNewlines` might be slower than necessary #231

Open sjakobi opened 2 years ago

sjakobi commented 2 years ago

https://github.com/quchen/prettyprinter/blob/0dbe08f65468697b729d5e05c98c89a58a42486b/prettyprinter/src/Prettyprinter/Internal.hs#L468-L477

It seems that this function would allocate a new Text value in order to perform the T.null check on it. GHC may be able to optimize this allocation away, but it seems fragile.

sjakobi commented 2 years ago

Apparently this issue was investigated before: https://github.com/quchen/prettyprinter/blob/0dbe08f65468697b729d5e05c98c89a58a42486b/prettyprinter/bench/FasterUnsafeText.hs