-
Notifications
You must be signed in to change notification settings - Fork 182
Add fromArrayMonolithic #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
12a2eeb
to
68d58e2
Compare
For GHC, this should let us create a sequence out of an array without having any stray pointers to the array in the sequence.
68d58e2
to
6ce774c
Compare
Note: if you're concerned about depending on |
After a lot of trouble, I finally figured out how to test this properly, and it works: holding on to a split-off piece of a sequence produced by The testing code (compile it with module Main where
import Prelude hiding (splitAt)
import Data.Array hiding (index)
import Data.Sequence
import Control.Exception
import Control.DeepSeq
import GHC.Stats
import System.Mem (performMajorGC)
import qualified Data.Foldable as F
sillyArray :: Int -> Array Int Int
sillyArray n = listArray (0,n-1) [0 .. n-1]
testFromArray :: Int -> String -> (Array Int Int -> Seq Int) -> IO ()
testFromArray size name fa = do
putStrLn $ "Testing " ++ name
let sm = case splitAt 10 . fa $ sillyArray size of
(small, large) -> large `deepseq` small
evaluate sm
stats1 <- getGCStats
putStrLn $ "Bytes used before GC: " ++ show (currentBytesUsed stats1)
performMajorGC
stats2 <- getGCStats
putStrLn $ "Bytes used after GC: " ++ show (currentBytesUsed stats2)
putStrLn $ "Result: " ++ show (F.sum sm)
main = do
putStrLn "How large should the array be?"
size <- readLn
testFromArray size "fromArray" fromArray
testFromArray size "fromArrayMonolithic" fromArrayMonolithic |
We should also test how this |
Allocation actually goes down quite a bit when using State instead of ST.
|
Personally, I am against this. Why having two 'fromArray' functions? Also, what is the difference between In any case, this is API change, so please propose to libraries@haskell if you want to pursue this. |
Because they have very different performance tradeoffs.
No. fromArrayMonolithic does not force any of the array elements. It just
Will do.
|
I find the name confusing. Does this just create an element-strict |
It does the latter (the careful thing). I guess changing fromArray is an |
The monolithic version can also be expanded to grab a limited slice, which |
Er .... actually, |
Personally I am not happy about exporting two fromArray functions, so I would agree with modifying Nevertheless, we are not using Personally, I would even consider getting rid of GHC-specific stuff in |
I'm not happy with the |
Well it is my mistake I did not insist on proposal to libraries@haskell before merging the first Nevertheless, we are probably stuck with |
Insisting on bureaucratic process doesn't always make things work better, but perhaps this time it would have. There is a huge time-vs-space safety tradeoff for |
I generally agree with @foxik here. It would help to clearly show the benefits of having both (i.e. with benchmarks). We also need to be careful so we measure the right thing. Deferring lots of things lazily can often give performance that we don't see in real programs (where we typically force the elements eventually and suffer higher GC costs down the line due to holding on to thunks.) |
I can put benchmarks together for sure. In this case, deferring things lazily is a pretty clear performance win for some reasonably likely situations. In particular, it's extremely common to build a structure (e.g., a |
It sounds like you have a good benchmark then. :) Please add it to the benchmark suite and post the results here (including the naive |
The bureaucratic process you are referring to has a reasonably good meaning -- on one side, it allows the community to express its oppinion, and on the other side, it makes the proposal more explicit and usually causes that the alternatives are spelled out and considered; in this situation, we probably would have discussed the fast_but_keeping_reference vs slow_but_no_references approaches and settle on one of them or decided that we need both. |
@foxik Yes, you are right. It can definitely be helpful sometimes. Sometimes it just bogs down in silly bickering, which does not negate the fact that sometimes it is helpful. I made a mistake here, and I'm sorry. |
There is no need to feel sorry -- the mistake of adding I understand you can feel that the library sumission process is blocking and slowing down your work. But there is a good reason for it, because the widely used packages like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somewhat agree that this should be discussed on the libraries list.
I'll "request changes" to clarify that this discussion should happen before the PR could be merged.
For GHC, this should let us create a sequence out of an array
without having any stray pointers to the array in the sequence.