Skip to content

Instantly share code, notes, and snippets.

Motivation

Long compilation times are a challenge for large Haskell projects. After tricks like giving GHC more memory are exhausted, users have a few levers within their code to speed up compilation:

  1. Reducing the time it takes to compile a module (e.g. removing unnecessary deriving statements, deleting unused code, etc.)
  2. Improving parallelism, which currently is done at the module level.
  3. Improving caching via incremental builds (mostly unrelated to this feature request)

However, users don't have great insight into what modules are slow to compile, and where compilation is bottlenecked on fewer than the available CPU cores, leading to fruitless StackOverflow questions like this one: https://stackoverflow.com/questions/47444097/is-there-a-way-to-profile-compilation-time-per-module-with-ghc

master
Running 1 benchmarks...
Benchmark persistent-th-bench: RUNNING...
benchmarking mkPersist/From File
time 606.2 μs (578.8 μs .. 631.0 μs)
0.963 R² (0.939 R² .. 0.978 R²)
mean 942.0 μs (820.5 μs .. 1.092 ms)
std dev 529.6 μs (428.2 μs .. 641.2 μs)
variance introduced by outliers: 99% (severely inflated)
test/main.hs:(41,124)-(56,2): Splicing expression
template-haskell-2.14.0.0:Language.Haskell.TH.Quote.quoteExp
persistUpperCase
"\n\
\Person json\n\
\ name Text\n\
\ age Int Maybe\n\
\ foo Foo\n\
\ address Address\n\
\ deriving Show Eq\n\
@MaxGabriel
MaxGabriel / PULL_REQUEST_TEMPLATE.md
Created December 18, 2019 13:34
Mercury PR template

Testing Plan / How I Tested

  • Wrote a test
  • Tested locally (running SHA)
  • Tested on staging (running SHA)
  • Will test in production

Database

@MaxGabriel
MaxGabriel / gist:9e757f2da60ac53b45bb06b2b097d86b
Last active October 31, 2019 22:45
persistent-postgresql case insensitive text
-- First enable citext in psql: CREATE EXTENSION IF NOT EXISTS citext;
-- Create Model/CustomTypes.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Model.CustomTypes where
❄️ ✔︎ ~/D/M/h/mercury-web-backend> cabal build 15:31:54
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.
Resolving dependencies...
Configuring mercury-web-backend-0.0.0...
clang-5.0: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
Preprocessing library for mercury-web-backend-0.0.0..
Building library for mercury-web-backend-0.0.0..
[ 1 of 141] Compiling AWS.Types ( src/AWS/Types.hs, dist/build/AWS/Types.o )
stgEqType: unequal
@MaxGabriel
MaxGabriel / th.hs
Created February 27, 2018 02:11
Without helper functions
derivePostgresEnum :: String -> String -> Q [Dec]
derivePostgresEnum s postgresType = do
ss <- [|SqlOther (pack postgresType)|]
tpv <- [|PersistText . pack . show|]
fpv <- [|\dt v ->
case fromPersistValue v of
Left e -> Left e
Right s' ->
case reads $ unpack s' of
(x, _):_ -> Right x
maximiliantagher@Maximilians-MBP ~/D/M/mercury-web> git diff yarn.lock
diff --git a/yarn.lock b/yarn.lock
index 441ccf1..b1df352 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -188,13 +188,14 @@
version "6.0.90"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.90.tgz#0ed74833fa1b73dcdb9409dcb1c97ec0a8b13b02"
-"@types/qrcode-generator@^0.0.16":
@MaxGabriel
MaxGabriel / gist:2a7116641ef32653618136473a699636
Created January 24, 2018 16:26
cabal install HsOpenSSL redirected to handle
cabal: Entering directory '/var/folders/v7/5k06hq7d3wbb4cvk8smv6kl00000gn/T/cabal-tmp-26452/HsOpenSSL-0.11.4.11'
[1 of 1] Compiling Main ( /var/folders/v7/5k06hq7d3wbb4cvk8smv6kl00000gn/T/cabal-tmp-26452/HsOpenSSL-0.11.4.11/dist/setup/setup.hs, /var/folders/v7/5k06hq7d3wbb4cvk8smv6kl00000gn/T/cabal-tmp-26452/HsOpenSSL-0.11.4.11/dist/setup/Main.o )
Linking /var/folders/v7/5k06hq7d3wbb4cvk8smv6kl00000gn/T/cabal-tmp-26452/HsOpenSSL-0.11.4.11/dist/setup/setup ...
Configuring HsOpenSSL-0.11.4.11...
Flags chosen: macports-openssl=False, homebrew-openssl=False, fast-bignum=True
Dependency base ==4.10.0.0: using base-4.10.0.0
Dependency bytestring ==0.10.8.2: using bytestring-0.10.8.2
Dependency integer-gmp ==1.0.1.0: using integer-gmp-1.0.1.0
Dependency network ==2.6.3.2: using network-2.6.3.2
Dependency time ==1.8.0.2: using time-1.8.0.2
@MaxGabriel
MaxGabriel / gist:7889879980cd6525038ceeea80c76f87
Created January 24, 2018 16:25
cabal install HsOpenSSL --verbose
maximiliantagher@Maximilians-MacBook-Pro ~> cabal install HsOpenSSL --verbose
/usr/local/bin/alex --version
/usr/bin/gcc -dumpversion
looking for tool haddock near compiler in /usr/local/bin
found haddock in /usr/local/bin/haddock
/usr/local/bin/haddock --version
/usr/local/bin/happy --version
looking for tool hpc near compiler in /usr/local/bin
found hpc in /usr/local/bin/hpc
/usr/local/bin/hpc version