[GHC] #9447: Add support for resizing `MutableByteArray#`s
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: | Differential Revisions: Phab:D133 -------------------------------------+------------------------------------- This is motivated by #9281 which changes how memory is allocated, and gives rise to the need to be able to efficiently shrink or grow `MutableByteArray#`s before they're frozen into `ByteArray#` while retaining their original byte content to avoid a major bottle-neck. This ticket is for tracking/documenting all changes related to this new facility. Here's the current road-map: 1. Implement {{{#!hs shrinkMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> State# s resizeMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #) }}} (see Phab:D133) 2. As suggested by Johan, {{{#!hs getSizeofMutableByteArray# :: MutableByteArray# s -> State# s -> (# State# s Int# #) }}} This is similar in spirit to `numCapabilities` and `getNumCapabilities`. Add a deprecate pragma (or equivalent) for `sizeofMutableByteArray#`. Add a note to `sizeofMutableByteArray#` stating that it's unsafe in the presence of calls to resize-operations on the same MBA. 3. Submit patches to upstream libraries replacing calls to `sizeofMutableByteArray#` with `getSizeofMutableByteArray#` 4. Investigate how to provide in-place (zero-copy) growing of MBAs (step 1. only implements in-place shrinking). -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: | Blocked By: None/Unknown | Related Tickets: Test Case: | Blocking: | Differential Revisions: Phab:D133 | -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"246436f13739593d2a211ceb830393338118ca4d/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="246436f13739593d2a211ceb830393338118ca4d" Implement {resize,shrink}MutableByteArray# primops The two new primops with the type-signatures resizeMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #) shrinkMutableByteArray# :: MutableByteArray# s -> Int# -> State# s -> State# s allow to resize MutableByteArray#s in-place (when possible), and are useful for algorithms where memory is temporarily over-allocated. The motivating use-case is for implementing integer backends, where the final target size of the result is either N or N+1, and only known after the operation has been performed. A future commit will implement a stateful variant of the `sizeofMutableByteArray#` operation (see #9447 for details), since now the size of a `MutableByteArray#` may change over its lifetime (i.e before it gets frozen or GCed). Test Plan: ./validate --slow Reviewers: ezyang, austin, simonmar Reviewed By: austin, simonmar Differential Revision: https://phabricator.haskell.org/D133 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D133 -------------------------------------+------------------------------------- Changes (by thomie): * failure: None/Unknown => Runtime performance bug * type: bug => feature request -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D133 -------------------------------------+------------------------------------- Comment (by bgamari): See Phab:D1139 for an implementation of `getSizeofMutableByteArray#`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D133, | Phab:D1139 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: Phab:D133 => Phab:D133, Phab:D1139 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D133, | Phab:D1139 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"9e8562ae02701270e2c1dfcee3279d862dc5b7b6/ghc" 9e8562a/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="9e8562ae02701270e2c1dfcee3279d862dc5b7b6" Implement getSizeofMutableByteArrayOp primop Now since ByteArrays are mutable we need to be more explicit about when the size is queried. Test Plan: Add testcase and validate Reviewers: goldfire, hvr, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1139 GHC Trac Issues: #9447 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9447: Add support for resizing `MutableByteArray#`s -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D133, | Phab:D1139 -------------------------------------+------------------------------------- Comment (by bgamari): hvr, I discussed this briefly with Simon Marlow in the meeting last week and he indicated that it may not be too tricky to implement efficient growing of ByteArrays. Perhaps you'd like to discuss this with him (assuming you still believe this is a worthwhile optimization)? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9447#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC