haskell / haskell/bytestring

Builder literals are noticeably slower to compile than ByteString literals

Open
#496 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Haskell
Stars
301
Forks
144
Avg merge
7d 22h
Merged PRs (30d)
1

Description

This is in relation to a [recent discussion on the Haskell Discourse](https://discourse.haskell.org/t/string-literals-and-compilation-speed/4161). There were two similar-but-different issues discussed in that thread, so I am filing two GitHub issues. (The other one is #495.)

This issue is that it's noticeably faster (at compile time) to use the `IsString` instance for `ByteString` and then call [byteString](https://hackage.haskell.org/package/bytestring-0.11.2.0/docs/Data-ByteString-Builder.html#g:4) on it, than it is to use the `IsString` instance for `Builder` directly. That seems surprising to me, and probably indicates an inefficiency in the `IsString` instance for `Builder`.

For example:

```
[2 of 3] Compiling Experiment.Medium ( 1.53 s)
[3 of 3] Compiling Experiment.Slow ( 2.18 s)
```

`Slow` is using the `IsString` instance for `Builder`, while `Medium` is using the `IsString` instance for `ByteString`, and then converting it to a `Builder`.

The code that demonstrates this behavior is in my [strlit-test](https://github.com/ppelleti/strlit-test) repository.

I'm using GHC 8.10.7 and `bytestring-0.10.12.0`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.