Opened 6 years ago

Closed 6 years ago

#7923 closed task (fixed)

Optimization for takeMVar/putMVar when MVar left empty

Reported by: ezyang Owned by: ezyang
Priority: normal Milestone:
Component: Runtime System Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Right now, we always add an MVar to the mutable list when we takeMVar/putMVar. However, this is unnecessary when the MVar is left empty. This patch arranges that we don't add the MVar to the mutable list in those cases. I've validated the patch but haven't checked performance changes yet.

Attachments (1)

0001-Optimization-for-takeMVar-putMVar-when-MVar-left-emp.patch (4.8 KB) - added by ezyang 6 years ago.
Patch

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by igloo

difficulty: Unknown
Status: newpatch

comment:2 Changed 6 years ago by igloo

Shouldn't this hunk:

-        unlockClosure(mvar, stg_MVAR_DIRTY_info);
+        unlockClosure(mvar, info);
+        // escape without dirty_MVar!

use stg_MVAR_CLEAN_info instead of info? And likewise in stg_tryTakeMVarzh.

comment:3 Changed 6 years ago by igloo

ezyang pointed out that it'll be on a mutable list, so it's not as simple as just marking it clean here.

comment:4 Changed 6 years ago by ian@…

commit 5d9e686c30a00be08a04d9fd1c860994153a1f7a

Author: Ian Lynagh <ian@well-typed.com>
Date:   Sat Jun 15 13:19:21 2013 +0100

    Optimization for takeMVar/putMVar when MVar left empty; fixes #7923
    
    We only need to apply the write barrier to an MVar when it acquires
    a reference to live data; when the MVar is left empty in the case
    of a takeMVar/putMVar, we can save a memory reference.
    
    Patch from Edward Z. Yang.

 rts/PrimOps.cmm |   49 +++++++++++++++++++++++++++++--------------------
 1 files changed, 29 insertions(+), 20 deletions(-)

comment:5 Changed 6 years ago by igloo

Resolution: fixed
Status: patchclosed

Applied, thanks!

Note: See TracTickets for help on using tickets.