Open sjakobi opened 4 years ago
A little helper function that reports the frequency of constructors would be useful here.
I have used countFrequencies
on some dhall
expressions (as usual):
In some expressions Column
and Nesting
(introduced quite surely by align
) appear more frequently. This is Prelude.JSON.renderYAML
:
I do wonder whether counting constructor by traversing the entire tree is the right thing to do though. Maybe it would be better to hook into e.g. layoutWadlerLeijen
and count the constructors we pattern-match on there.
In https://github.com/quchen/prettyprinter/commit/e79bb67f5e05f9dc9d0e08335a2517ea392664b0 I have moved the Cat
and Annotated
constructors into the first constructor group. I haven't seen a significant performance difference from this change though. Better benchmarks (https://github.com/quchen/prettyprinter/issues/118) would be helpful!
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 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, whileFail
andFlatAlt
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.