Text append performance in Haskell

831 views Asked by At

I realized that appending multiple instances of Text in Haskell is much slower than concatenating a list of texts. For instance, T.concat ["'", txt, "'"] is almost twice faster than

"'" `T.append` txt `T.append` "'"

This is because any append actually creates a new intermediate instance of Text, while concat makes a single instance.

I am working on a project that does a lot of text appends. I wonder if there is a simple way to optimize such cases? One option is to replace all such occurrences by hand. The other option is to use GHC rewriting rules to convert them to the concat form. Is the rewriting rule a reasonable option? How can I write such a rule then? What are the other options?

0

There are 0 answers