haskell / haskell/binary

get for UArray blows the heap for large arrays

Aperta
#34 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Haskell
Stelle
120
Fork
70
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

``` haskell
instance (Binary i, Ix i, Binary e, IArray UArray e) => Binary (UArray i e) where
get = do
bs <- get
n <- get
xs <- getMany n
return (listArray bs xs)
```

getMany is fully strict in the list, since it uses an accumulator and reverses it at the end. The intermediate xs list can be huge in cases where the eventual UArray is much more manageable (eg 28M Booleans).

Two questions:

1) Is there a known alternative for (un)serializing UArrays to(from) disk? Such an alternative would make this Issue far less important.

2) Have you considered a version that serializes the bytes directly? I drafted one up; it's tremendously more efficient, though I'm concerned about robustness wrt endianness etc. Furthermore, it requires a base monad that can mutate arrays, which requires an "unsafe" invocation. And lastly it's not portable, using ghc-prim.

HTH. Thanks.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.