How expensive are MVars ?

Simon Marlow simonmar at microsoft.com
Mon Jan 17 07:32:20 EST 2005


On 13 January 2005 23:36, Nick Main wrote:

> I'm planning to implement a small OO language on top of GHC (think
> JavaScript) and need to decide on how to implement the mutable object
> graph that is required.
> 
> The two approaches I'm considering are:
>  - something on top of Data.Graph
>  - using MVars as the object references.
> 
> The MVar approach is the most appealing, since it would also allow the
> OO language to contain threads.  How expensive is an MVar access (in
> GHC), compared to the graph navigation that would be required to
> resolve a reference using Data.Graph ?
> 
> I know this is a fairly nebulous question, but any comments or
> suggestions are appreciated.

So here's a nebulous answer: I don't know, measure it :-)

Each MVar operation involves a function call right now, so you might
class it as "expensive".

Personally for your application, I think I'd use a mutable array to
represent the heap.  That amounts to almost the same as using
Data.Graph, but I imagine you'll need the mutability for speed.  Perhaps
providing a mutable Graph data structure implemented using an array
would be a nice abstraction.

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list