haskell-prettyprinter / haskell-prettyprinter/prettyprinter

Optimize the order of constructors in Doc

Open
#125 1 comment 0 reactions 0 assignees View on GitHub
Performance
Dominant language
Haskell
Stars
309
Forks
43
Avg merge
21h 25m
Merged PRs (30d)
1

Description

Starting with GHC 8.10, handling the first 6 constructors of `Doc` should be slightly faster than handling the other 7. See [this GHC patch](https://gitlab.haskell.org/ghc/ghc/commit/9897e8c8ef0b19a9571ef97a1d9bb050c1ee9121) for the background on this.

By shuffling around the order of constructors, we might be able to speed up typical documents.

For example, `Cat` should probably be in the first group, while `Fail` and `FlatAlt` could be in the second group without much performance degradation. `Annotated` could also be a candidate for the first group.

A little helper function that reports the frequency of constructors would be useful here.

`SimpleDocStream` fortunately has 7 constructors, which is exactly the number of constructor tags on 64-bit systems. 0 is the tag for unevaluated thunks.

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.