[GHC] #9067: Optimize clearNursery by short-circuiting when we get to currentNursery
#9067: Optimize clearNursery by short-circuiting when we get to currentNursery ------------------------------+-------------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: new Priority: low | Milestone: Component: Runtime | Version: 7.9 System | Operating System: Unknown/Multiple Keywords: | Type of failure: Runtime performance bug Architecture: | Test Case: Unknown/Multiple | Blocking: Difficulty: Unknown | Blocked By: | Related Tickets: | ------------------------------+-------------------------------------------- This is a note to myself so I don't forget about this. Essentially, we can do something like this (this particular patch variant untested): {{{ diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index 36776b9..0311042 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -598,6 +598,11 @@ clearNursery (Capability *cap) ASSERT(bd->gen_no == 0); ASSERT(bd->gen == g0); IF_DEBUG(sanity,memset(bd->start, 0xaa, BLOCK_SIZE)); + if (bd == cap->r.rCurrentNursery) { + IF_DEBUG(sanity, for (bd = bd->link; bd; bd = bd->link) + ASSERT(bd->free == bd->start)); + break; + } } } } }}} This is due to invariants about how we manage the currentNursery pointer. But we need a note about it, and I need to test it more carefully. This optimization probably doesn't help too much on normal GHC, but when I have lots of nurseries it helps quite a bit. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9067> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9067: Optimize clearNursery by short-circuiting when we get to currentNursery --------------------------------------------+------------------------------ Reporter: ezyang | Owner: ezyang Type: task | Status: new Priority: low | Milestone: Component: Runtime System | Version: 7.9 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime performance bug | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: --------------------------------------------+------------------------------ Comment (by simonmar): Andreas Voellmy and I talked about some similar ideas. I doubt that you want to rely on `CurrentNursery`, because we want to reset that after every GC, but instead I think the right approach is to assume that every block from `CurrentNursery` onwards needs to have its free pointer reset before we use it. It's a somewhat subtle invariant and something else we have to get right, but the win seems to be worthwhile. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9067#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9067: Optimize clearNursery by short-circuiting when we get to currentNursery -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: new Priority: low | Milestone: Component: Runtime | Version: 7.9 System | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: Phab:D318 | -------------------------------------+------------------------------------- Changes (by simonmar): * differential: => Phab:D318 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9067#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9067: Optimize clearNursery by short-circuiting when we get to currentNursery -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: closed Priority: low | Milestone: Component: Runtime | Version: 7.9 System | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: Phab:D318 | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => fixed Comment: {{{ commit e22bc0dedb9e9da0176ad7ce4a74acbefedc7207 Author: Simon Marlow <marlowsd@gmail.com> Date: Tue Oct 7 10:30:36 2014 +0100 Make clearNursery free Summary: clearNursery resets all the bd->free pointers of nursery blocks to make the blocks empty. In profiles we've seen clearNursery taking significant amounts of time particularly with large -N and -A values. This patch moves the work of clearNursery to the point at which we actually need the new block, thereby introducing an invariant that blocks to the right of the CurrentNursery pointer still need their bd->free pointer reset. This should make things faster overall, because we don't need to clear blocks that we don't use. Test Plan: validate Reviewers: AndreasVoellmy, ezyang, austin Subscribers: thomie, carter, ezyang, simonmar Differential Revision: https://phabricator.haskell.org/D318 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9067#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9067: Optimize clearNursery by short-circuiting when we get to currentNursery -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: task | Status: closed Priority: low | Milestone: 7.10.1 Component: Runtime | Version: 7.9 System | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: performance bug | Test Case: | Blocking: | Differential Revisions: Phab:D318 | -------------------------------------+------------------------------------- Changes (by ezyang): * milestone: => 7.10.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9067#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC