Commit 9adcd3c
authored
Faster List.map (#157)
* List Functor: mix unrolled and reverse map
Addresses #131
The relevant chunk sizes (5 for the initial list segment), (3 for the
tail-recursive remainder) were arrived at through benchmarked
experimentation, mapping a simple (_ + 1) through lists of various
sizes.
Relevant figures:
list of 1000 elems: 142.61 μs -> 36.97 μs
list of 2000 elems: 275.17 μs -> 55.33 μs
list of 10000 elems: 912.73 μs -> 208.39 μs
list of 100000 elems: 34.56 ms -> 1.24 ms
The ~30x speed increase for long lists is probably explained by the lack
of GC thrashing with this approach.
Benchmarked on 2017 Macbook Pro, 2.3 GHz Intel Core i5, 8 GB RAM.
macOS Sierra 10.12.6
node v8.9.1
* initial benchmarks for List.map
2017 MacBook Pro 2.3 GHz Intel Core i5, 8 GB 2133 MHz LPDDR3
Node v8.9.1
List
====
map
---
map: empty list
mean = 1.31 μs
stddev = 11.87 μs
min = 799.00 ns
max = 375.82 μs
map: singleton list
mean = 2.40 μs
stddev = 11.03 μs
min = 1.03 μs
max = 342.18 μs
map: list (1000 elems)
mean = 143.41 μs
stddev = 225.12 μs
min = 97.16 μs
max = 2.03 ms
map: list (2000 elems)
mean = 274.16 μs
stddev = 295.84 μs
min = 199.66 μs
max = 2.06 ms
map: list (5000 elems)
mean = 531.84 μs
stddev = 512.61 μs
min = 229.45 μs
max = 2.95 ms
map: list (10000 elems)
mean = 895.24 μs
stddev = 777.87 μs
min = 464.59 μs
max = 2.94 ms
map: list (100000 elems)
mean = 33.45 ms
stddev = 7.65 ms
min = 22.07 ms
max = 63.47 ms
* style tweak
* test stack-safety of strict map
* lower unrolled map iteration limit
this lower the probability of stack-size troubles
* restore un-exported functions from Data.List.Types
* add failing map test
* fix a logic error in List.map chunkedRevMap
* make map stack safe(r) again
begin with reverse unrolled map
* Update for 0.12 id -> identity
* Update benchmark code for 0.12
* Remove outdated comment
* 🤦♂️1 parent 6629e0c commit 9adcd3c
File tree
6 files changed
+104
-4
lines changed- bench
- Bench/Data
- src/Data/List
- test/Test/Data
6 files changed
+104
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
2 | 8 | | |
3 | 9 | | |
4 | 10 | | |
| |||
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
71 | 99 | | |
72 | 100 | | |
73 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
367 | 373 | | |
368 | 374 | | |
369 | 375 | | |
| |||
0 commit comments