Help with optimization/profiling
To look at core I like to put this at the top of the file:
{-# OPTIONS_GHC -ddump-simpl -dsuppress-all -dno-suppress-type-signatures -dno-typeable-binds -ddump-to-file #-}
Afterwards I do a find . -name "*.dump-simpl" which shows that on my machine it generated the dump at this location:
% find . -name "*.dump-simpl"
./dist-newstyle/build/aarch64-osx/ghc-9.10.3/hs-plugui-1.0.1/x/main/build/main/main-tmp/app/Main.dump-simpl
That file contains the Core dump which is the intermediate language that GHC has applied most of its optimizations to.
I do notice that it doesn’t give much extra information in this case. There is quite some aggressive inlining which you can work around by adding {-# NOINLINE #-} to imageBytes, generateImage and encodePalettedPng, which doesn’t really change the running time.
In this case I think there’s not much to win from looking atimageBytes because it is basically just calling two library functions.
So optimizing this further would basically mean optimizing the underlying libraries.
Discussion in the ATmosphere