-XStrictData
might be useful as a quick check, but I think it’s better to have explicit bangs in record fields.
If you grep a large codebase, you will see the field declaration, not the LANGUAGE StrictData
somewhere at the top of the module.So you may mistakenly think that the field is lazy. An explicit bang helps to disambiguate this.
BTW, a related performance pitfall is to use Record { field :: {-# UNPACK #-} !Int }
and then send the field
to a non-inlined function that expects a boxed value. This will cause allocation (boxing) and may actually reduce performance.
There’s no royal road to performance. Everything is lazy is usually faster, but you need to care about accumulators, and it may be not faster in raw number crunching. Making everything strict kills a lot of expressiveness and, counter-intuitively, usually makes things slower.
BTW #2: For the “Haskell must be strict” folk, see a take from Edward Kmett on how laziness is necessary for performance in a pure language (basically a short description of the chapter “Amortization and persistence via lazy evaluation” from Okasaki’s book).