andrewthad / packed

Unpinned byte arrays in GHC haskell
BSD 3-Clause "New" or "Revised" License
22 stars 3 forks source link

fixedparser optimisation (rewrite rules) is a bit fiddly #11

Open chessai opened 5 years ago

chessai commented 5 years ago

look at the following gist: https://gist.github.com/chessai/39dfce8b2a56a05f3c48bd49ac52d066

it contains pairs of .hs files and their core output as a result of \module -> ghc module -O2 -ddump-simpl -dsuppress-all -fforce-recomp

each .hs file contains a parser for the 'Foo' datatype, defined as

data Foo = Foo Word64 Word64 Word64 Word64

in foo.hs, we use full applicative style. the core output is completely optimal.

in fooM.hs, we use monadic style. the core output is optimal for the first two parses, but the second two fail to optimise.

in fooA.hs, we use monadic style, but with -XApplicativeDo enabled. the core output is optimal for the latter three parses, but the first fails to optimise.

chessai commented 5 years ago

actually, the first foo.core (applicative style) output is identical to the core when -XApplicativeDo is enabled. but when i change the fields of Foo to be Word32, the core becomes optimal in all cases.

chessai commented 5 years ago

ah, i was missing an INLINE pragma on fixedBigEndianWord64. this fixed the issue in the previous comment about the core being optimal in all cases (it's not now).

so, to recap where i am now:

foo.hs - optimal fooM.hs - optimal except in second two parses fooA.hs - optimal

chessai commented 5 years ago

i'm going to compare across word-types now

chessai commented 5 years ago

for the word32 type, the monadic style (sans applicative-do) performs better than the word64 type

chessai commented 5 years ago

https://gist.github.com/chessai/a1090722d0a16d2f9c23e314a5b53a58 this gist is more immediately comprehensive than me talking