When thinking about e.g. #959, it always bugged me that we use Strings in so many places. This PR removes the two primary occurences:
Package and operator names in the fixity logic.
Here, we now use PackageName from Cabal-syntax (as that is where we get the package names from) and a newtype wrapper around ShortByteString for operator names (could also use FastString or ShortText, should be rather easy to change).
As the input type to the ormolu function, now Text.
For this, I wrote an efficient conversion function Text -> StringBuffer.
Apart from better type safety, we get speedups:
For fixity parsing overhead (see #959 for the setup, ormolu is 0.5.2.0 here):
Command
Mean [ms]
Min [ms]
Max [ms]
Relative
ormolu --no-cabal test-a.hs
1.5 ± 0.4
0.9
4.5
1.00
result-nostrs/bin/ormolu --no-cabal test-a.hs
2.6 ± 0.7
1.7
7.2
1.69 ± 0.62
ormolu --no-cabal test-b.hs
37.1 ± 2.1
34.5
52.3
24.37 ± 6.46
result-nostrs/bin/ormolu --no-cabal test-b.hs
20.1 ± 1.1
18.6
22.6
13.23 ± 3.50
ormolu --no-cabal test-c.hs
84.8 ± 3.2
82.0
96.4
55.71 ± 14.57
result-nostrs/bin/ormolu --no-cabal test-c.hs
60.2 ± 3.2
57.0
75.0
39.58 ± 10.46
Test suite execution time also dropped by 10% from 940ms to 840 ms.
Retroactive cause: Closes #972
When thinking about e.g. #959, it always bugged me that we use
String
s in so many places. This PR removes the two primary occurences:Package and operator names in the fixity logic.
Here, we now use
PackageName
fromCabal-syntax
(as that is where we get the package names from) and a newtype wrapper aroundShortByteString
for operator names (could also useFastString
orShortText
, should be rather easy to change).As the input type to the
ormolu
function, nowText
.For this, I wrote an efficient conversion function
Text -> StringBuffer
.Apart from better type safety, we get speedups:
For fixity parsing overhead (see #959 for the setup,
ormolu
is 0.5.2.0 here):ormolu --no-cabal test-a.hs
result-nostrs/bin/ormolu --no-cabal test-a.hs
ormolu --no-cabal test-b.hs
result-nostrs/bin/ormolu --no-cabal test-b.hs
ormolu --no-cabal test-c.hs
result-nostrs/bin/ormolu --no-cabal test-c.hs
Test suite execution time also dropped by 10% from 940ms to 840 ms.