Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
MaxGabriel / DeriveLoadAllModels.hs
Created Nov 22, 2020
Template Haskell to load all Persistent models, stream them from the database, and validate they deserialize correctly
View DeriveLoadAllModels.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
module Mercury.Database.Persist.DeriveLoadAllModels (mkLoadAllModels) where
import ClassyPrelude
import Control.Monad.Logger (MonadLogger, logInfoN)
import Data.Acquire (with)
import Data.Conduit (fuse, runConduit)
import qualified Data.Conduit.Combinators as Conduit
import qualified Data.Kind as K
@MaxGabriel
MaxGabriel / gist:167eadb8548286177ffbea95ca73757d
Created Jun 21, 2020
ghcid bug user error (could not create file system event stream)
View gist:167eadb8548286177ffbea95ca73757d
This file has been truncated, but you can view the full file.
(130) ❄️ ~/D/M/h/mercury-web-backend> ghcid -o ghcid.txt --command 'cabal new-repl lib:mercury-web-backend' --allow-eval --warnings --verbose 20:58:35
%OS: darwin
%ARCH: x86_64
%VERSION: 0.7.6
Loading cabal new-repl lib:mercury-web-backend ...
%STDOUT: Build profile: -w ghc-8.6.5 -O0
%STDOUT2: Build profile: -w ghc-8.6.5 -O0
Build profile: -w ghc-8.6.5 -O0
%STDOUT: In order, the following will be built (use -v for more details):
@MaxGabriel
MaxGabriel / gps-parser.hs
Created May 9, 2020
Degrees minutes seconds parser in haskell, for parsing e.g. 37 deg 8' 21.26" N, 80 deg 34' 41.84" W
View gps-parser.hs
latToDecimal :: DMSLat -> Double
latToDecimal (DMSLat dms direction) =
let decimal = dmsToDecimal
in case direction of
North -> decimal
South -> decimal * -1
lonToDecimal :: DMSLat -> Double
lonToDecimal (DMSLon dms direction) =
let decimal = dmsToDecimal
View issue.md

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

View gist:5badd57a3ded7bac2ba43cc3c2a2a3b3
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)
View main.dump-splices
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\
View PULL_REQUEST_TEMPLATE.md

Testing Plan / How I Tested

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

Database

View gist:6bb94023688b05e12ec02ddccae28166
- aeson
- aeson-casing
- aeson-iproute
- aeson-pretty
- aeson-typescript
- amazonka
- amazonka-core
- amazonka-s3
- amazonka-sqs
- async
@MaxGabriel
MaxGabriel / parser.ts
Created Sep 24, 2018
Date parsing code
View parser.ts
import * as P from 'parsimmon'
import Day from '~/utils/Day'
import Month from '~/utils/Month'
const shortMonths = {
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
View gist:d0d524bff89ea8439e24aa356c0b7332
❄️ ✔︎ ~/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