Skip to content

Add primops for copying/cloning an array in the new codegen

Daniel Peebles's benchmarks show that copying arrays using a indexArray#/writeArray# loop is much slower than using a (new) primop that calls memcpy. In addition, cloning arrays is slower than it need to be due to newArray# filling the array with a default element, just to have all the elements be overwritten by the contents of the array being cloned.

I suggest we add the following primops:

copyArray#        ::        Array# a -> Int# -> MutableArray# s a -> Int# -> Int# -> State# s -> State# s
copyMutableArray# :: MutableArray# a -> Int# -> MutableArray# s a -> Int# -> Int# -> State# s -> State# s

cloneArray#        ::        Array#   a -> Int# -> Int# -> State# s -> (# State# s, Array# a #)
cloneMutableArray# :: MutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, MutableArray# s a #)

freezeArray# :: MutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, Array# a #)
thawArray#   ::        Array#   a -> Int# -> Int# -> State# s -> (# State# s, MutableArray# s a #)

Note that ByteArray# versions can be created using FFI calls to memcpy and thus don't need to be primops.

Trac metadata
Trac field Value
Version 7.0.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC johan.tibell@gmail.com, pumpkingod@gmail.com
Operating system
Architecture
Edited by tibbe
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information