Version française
Home     About     Download     Resources     Contact us    
Browse thread
announce: callbacks-0.1
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bardur Arantsson <spam@s...>
Subject: Re: announce: callbacks-0.1
On Fri, Sep 09, 2005 at 07:53:17AM +0200, Christophe Raffalli wrote:

>> Now, I'll freely admit that I haven't tested it specifically, but I
>>  suspect performance will be worse when using register_global_root
>>  to register callback closures instead of just using a mapping from
>>  "int" (or whatever type your callback identifier would be on the C
>>  side) to closures "stored" on the OCaml side. There was a post on
>>  this list not too long ago which exposed efficiency issues with 
>> register_global_root when registering lots and lots of roots.

> anyway, there should not be that many callbacks ?

That depends hugely on what kind of library you're wrapping. I did a
wrapper for libevent (events on file descriptors and other similar stuff
like alarms, etc.) and what ended up happening was that a 1) lot of the
time a relatively large amount of callbacks were registered, orm 2)
callbacks would be registered/unregistered a lot. I did try using
*_global_roots in my libevent wrapper, but the performance was awful
until I changed it to use an (fd->callback) hashtable on the OCaml side.

(In the case of file descriptors or similar objects you can try to be
more clever and just use an array of callbacks and use the file
descriptor as the index; I didn't bother with this in my wrapper library
since the performance was OK as it was).

> Moreover, I suspect (but may be wrong) that register_global_root () 
> is or could be optimized for closure on closed functions, and this 
> will be the case of most closure with my approach.

 From the implementation in globroots.c it would seem that
register_global_root is at least O(n) in the number of roots, and that
it has a large constant overhead compared to e.g. adding something to a
hashtable. So it may not be the fact that a closure may keep things
alive that's slowing it down, but rather just a slow implementation of 
register_global_root itself.

[--snip--]

-- 
Bardur Arantsson
<bardur@imada.sdu.dk>
<bardur@scientician.net>

- There are a thousand forms of subversion, all of them
interesting. But few, in my opinion, can equal the convenience
and immediacy of the cream pie.
                                                        Noël Godin