Closed barrucadu closed 7 years ago
Thanks for the investigation!
Profiling can have huge impacts on optimised code, both performance and memory use. Can you rebenchmark with "normal" flags (e.g. Cabal build)?
Compiled with just -rtsopts
, Foundation does better than it did, but Text still beats it in terms of total allocation (and maximum residency):
str/Str-ByteString.hs
1,666,312,648 bytes allocated in the heap
327,385,856 bytes copied during GC
4,698,224 bytes maximum residency (98 sample(s))
69,240 bytes maximum slop
12 MB total memory in use (0 MB lost due to fragmentation)
str/Str-Foundation.hs
2,495,373,664 bytes allocated in the heap
316,563,464 bytes copied during GC
2,875,192 bytes maximum residency (102 sample(s))
66,584 bytes maximum slop
9 MB total memory in use (0 MB lost due to fragmentation)
str/Str-Foundation-Unsafe.hs
2,495,311,344 bytes allocated in the heap
314,517,328 bytes copied during GC
2,862,040 bytes maximum residency (102 sample(s))
68,616 bytes maximum slop
9 MB total memory in use (0 MB lost due to fragmentation)
str/Str-String.hs
5,525,893,584 bytes allocated in the heap
2,666,256,056 bytes copied during GC
24,358,400 bytes maximum residency (285 sample(s))
701,024 bytes maximum slop
66 MB total memory in use (0 MB lost due to fragmentation)
str/Str-Text.hs
1,764,079,248 bytes allocated in the heap
308,773,880 bytes copied during GC
4,973,528 bytes maximum residency (101 sample(s))
1,224,600 bytes maximum slop
13 MB total memory in use (0 MB lost due to fragmentation)
The timing results were already from the unprofiled binaries.
@barrucadu I don't think maximum residency means what to do you think it means: less is better and foundation "wins" there, which is compounded by "total memory is use" which represent how many mblocks have been allocated (less is better there too). Can you also add which ghc version that you used for the benchmarks ?
Globally, while it would be nice to push down the number of bytes allocated, it's hard to make any comparative differences that means something between 2 differents codebase with this number (e.g. text vs foundation).
That being said, I'm sure it would be interesting to drive a new round of optimisation for weeder, in foundation in some near future.
I have no idea how I misread the maximum residency to think Text won there, whoops.
I'm using GHC 8.0.2.
The only metric users care about is total time and total memory in use - all the other details are really stuff to help developers optimise things. That said, I'd be surprised if decreasing the allocation rate didn't help foundation somewhere.
My guess given the timings is that String is vastly slower than the other approaches, but the majority of the time is not in String stuff.
I think the above benchmarks suggests foundation is the right approach - does everyone concur? I had planned to do a blog post comparing the options once the analysis had been done, so thanks @barrucadu
Yes, given the lower residency, Foundation does look like the right choice.
Agreed, awesome - always bet on @vincenthz! (Although if he could reduce the alloc rate it would almost certainly improve performance even more - tearing away from the rest of the pack).
I saw #25 and decided to try profiling the alternative strings in the
str
directory while running weeder on https://github.com/barrucadu/dejafu, four packages with 51 modules between them. Here's what I found:Timing results are from compiling without profiling, allocation results are from compiling with
-prof -fprof-auto
, so there may well be some optimisations being defeated.Text appears to use a little over half the memory of Foundation.Unsafe, with a very similar runtime.
The benchmark scripts are:
time:
allocation:
(where
pkgs.profiledHaskellPackages
is the Nix Haskell package set with libraries compiled with profiling turned on)