[GHC] #9696: readRawBufferPtr and writeRawBufferPtr allocate memory

GHC ghc-devs at haskell.org
Tue Dec 13 21:23:49 UTC 2016


#9696: readRawBufferPtr and writeRawBufferPtr allocate memory
-------------------------------------+-------------------------------------
        Reporter:  mergeconflict     |                Owner:
            Type:  bug               |               Status:  patch
        Priority:  low               |            Milestone:  8.2.1
       Component:  Compiler          |              Version:  7.8.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:  x86_64
 Type of failure:  Runtime           |  (amd64)
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D2813
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"cc2e3ec06ce5ac979ff2ecf453ad85b0e5ff326d/ghc"
 cc2e3ec0/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="cc2e3ec06ce5ac979ff2ecf453ad85b0e5ff326d"
 base: Make raw buffer IO operations more strict

 Ticket #9696 reported that `readRawBufferPtr` and `writeRawBufferPtr`
 allocated unnecessarily. The binding is question was,
 ```
 let {
   buf_s4VD [Dmd=<L,U(U)>] :: GHC.Ptr.Ptr GHC.Word.Word8
   [LclId, Unf=OtherCon []] =
       NO_CCS GHC.Ptr.Ptr! [ds1_s4Vy];
 } in
   case
       GHC.IO.FD.$wreadRawBufferPtr
           Main.main5
           0#
           0#
           buf_s4VD
           Main.main4
           Main.main3
           GHC.Prim.void#
   of ...
 ```
 The problem was that GHC apparently couldn't tell that
 `readRawBufferPtr` would always demand the buffer. Here we simple add
 bang patterns on all of the small arguments of these functions to ensure
 that worker/wrappers can eliminate these allocations.

 Test Plan: Look at STG produced by testcase in #9696, verify no
 allocations

 Reviewers: austin, hvr, simonmar

 Reviewed By: simonmar

 Subscribers: RyanGlScott, simonmar, thomie

 Differential Revision: https://phabricator.haskell.org/D2813

 GHC Trac Issues: #9696
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9696#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list