GHC State Hack: Reducing Allocation Costs in Low-Traffic Workloads
0 reputation · 19 Mar 2022, 20:15 UTC
GHC employs a "state hack" heuristic that assumes State# tokens are used linearly. While this typically improves throughput by enabling aggressive inlining and eta-expansion, it can lead to increased closure creation and prevent let-binding floating in specific code patterns.
For low-traffic workloads, these increased allocations may outweigh the throughput benefits. The -fno-state-hack flag provides a mechanism to disable this behavior, but the flag is applied globally across the compilation unit.
There is uncertainty regarding the optimal balance between allocation reduction and execution speed when this heuristic is disabled, particularly in environments where memory overhead is a primary cost driver.
- Does disabling the state hack consistently reduce total bytes allocated in low-traffic scenarios across GHC 9.0+?
- What are the specific trade-offs in execution time when
-fno-state-hackis used in conjunction with-fspecialise-aggressively?