Skip to content

Instantly share code, notes, and snippets.

andrewthad /
Created Aug 5, 2020
Case on Bytes without compiler support

This is an idea for how to case on a byte sequence without any special support from the compiler. The basic idea is explored in, but there code generation is used rather than TemplateHaskell. The idea is that, at compile time, generating a perfect hash function for all strings of the same length is a good way to pattern match on a sequence of bytes. Roughly, we have:

foo :: Bytes -> Bar
foo b = case B.length b of
  3 -> case hash3 b of
    Car | b == "car" -> ...
andrewthad /
Created May 24, 2020
T5030 SCC Profiling for BoxedRep
Sat May 23 19:57 2020 Time and Allocation Profiling Report (Final)
ghc +RTS -p -RTS -B/home/amartin/ghc-boxedrep-prof/lib/ghc- ./testsuite/tests/perf/compiler/T5030.hs
total time = 0.56 secs (558 ticks @ 1000 us, 1 processor)
total alloc = 711,938,744 bytes (excludes profiling overheads)
simplCast-simplCoercion GHC.Core.Opt.Simplify compiler/GHC/Core/Opt/Simplify.hs:1293:57-77 28.5 30.5
andrewthad / boxedrep.txt
Created May 18, 2020
T5030 built with ticky compiler before and after boxed rep
View boxedrep.txt
This file has been truncated, but you can view the full file.
'/home/amartin/ghc-boxedrep-ticky/lib/ghc-' '-B/home/amartin/ghc-boxedrep-ticky/lib/ghc-' '-O2' './testsuite/tests/perf/compiler/T5030.hs' +RTS '-rboxedrep.ticky'
ENTERS: 124184476 of which 124184476 (100.0%) direct to the entry code
[the rest indirected via Node's info ptr]
19582791 ( 15.8%) thunks
21067039 ( 17.0%) data values
0 ( 0.0%) normal indirections
andrewthad / T9020-ghc-882.dump.txt
Created Feb 24, 2020
Typechecker dump for T9020 in GHC 8.8.2 and in GHC-boxedrep
View T9020-ghc-882.dump.txt
checkFamInstConsistency [Prelude]
Tc2 (src)
tcExtendKindEnvList []
tcExtendKindEnvList []
tcDeriving False
tcDeriving 1 []
Adding instances:
View base64_benchmarks.txt
benchmarked encode/base64-bytestring/25
time 161.7 ns (152.6 ns .. 168.1 ns)
0.980 R² (0.944 R² .. 0.998 R²)
mean 178.6 ns (169.1 ns .. 216.5 ns)
std dev 55.41 ns (14.38 ns .. 113.1 ns)
variance introduced by outliers: 95% (severely inflated)
benchmarked encode/base64-bytestring/100
time 232.1 ns (228.7 ns .. 234.8 ns)
0.999 R² (0.998 R² .. 0.999 R²)

Haskell Questions

What are the benefits of a type system? Describe a problem that strong static typing helps prevent. Describe a problem that strong static typing does not help prevent.

What is recursion? What is well-founded recursion? What is a base case?

Define referential transparency. Why is this a desirable property of a function? What optimizations opportunities does it make possible?

View witherable_fusion_example.dump-simpl
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 444, types: 513, coercions: 11, joins: 0/4}
-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
$trModule4 = "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
andrewthad / ten_literals.hs
Created Nov 14, 2019
Ten ByteString Literals
View ten_literals.hs
{-# language OverloadedStrings #-}
{-# OPTIONS_GHC -O2 -fforce-recomp -ddump-simpl -dsuppress-all -ddump-to-file -ddump-cmm -ddump-asm #-}
module ConstantLength
( stringOne
, stringTwo
, stringThree
, stringFour
, stringFive
, stringSix
View ecs_records.hs
module Record where
-- This approach gives us everything we want except for a type-safe
-- way to project out subsets of columns. For these kinds of projections,
-- the user will need to manually project out each column, upcast them
-- to uncompressed arrays (if they aren't absent), logical AND any mask
-- vectors, and then pick the valid rows from the columns. This is
-- inconvenient, but this kind of projection is a niche use that currently
-- only happens in insight.
View block_leak.hs
{-# language BangPatterns #-}
{-# language MagicHash #-}
{-# language UnboxedTuples #-}
{-# OPTIONS_GHC -O2 -Wall -fforce-recomp #-}
import GHC.Exts
import GHC.IO (IO(..))
import System.Mem (performMajorGC)
You can’t perform that action at this time.