Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2003-11-14 21:23:19


"Matthew Wilson" <stlsoft_at_[hidden]> wrote in message
news:bovl1d$juh$1_at_sea.gmane.org...
> Hi Boosters
>
> I'm just doing some research on reference-counting, and contrasting
> self-counting types with externally counted types, the latter effected
with
> the rather excellent shared pointer technique.
>
> [As a side question, is it true that Nicolai Josuttis was the inventor of
> the technique?]
>
> Naturally, one of the shared pointer's I've used is boost::shared_ptr. The
> measurements have demonstrated some surprising performance characteristics
> for shared_ptr in particular, and I want to solicit the opinion of the
> expert's here before I make any bold claims, as some results are just too
> surprising for me to trust them.
>
> There are five types tested.
>
> 1. A self-counting type, using an ancient Synesis (my company) template
> ref-counting bolt-in class
> 2. A self-counting type, using a custom-written (for this test) template
> ref-counting bolt-in class
> 3. Externally counting, using boost::shared_ptr
> 4. Externally counting, using a custom-written (for this test) shared
> pointer type
> 5. Externally counting, using a custom-written (for this test) shared
> pointer type, which has a custom allocator for the shared count members
>
>

  results snipped. Shared_ptr did not do well.

> Naturally, the very big question is: what's happening to
boost::shared_ptr?
>
> In thread times, it performs 2-3 times worse than in single threaded
> scenarios (irrespective of whether they are built for single or multiple
> threads). However, in total time, it performs extremely poorly, up to 100
> times slower than some of the others! Clearly, there is some serious
> contention involved.
>
> There are three possibilities I have thought of:
>
> (i) It performs very poorly in multi-threaded sharing scenarios. If this
is
> the case, can any people more expert in Boost than me proffer an
explanation
> as to precisely the problem, and is any such person motivated to try and
> address the issue?
> (ii) The particular sharing scenario is well away from any real-world
> scenario in which boost::shared_ptr is likely to be used. If this is the
> case, why do four different implementations, representing two very
different
> reference-counting strategies, all maintain a consistent relative
> performance? What are the scenarios for which boost::shared_ptr is
> optimised?
> (iii) There are environment settings for which boost::shared_ptr will
> perform much better. If that's so, can someone help me out with
suggestions
> of what defines to make? Why are these settings not the default.
>
> I'd be very interested in your thoughts.
>
> Many thanks in advance.
>

    Have you tried getting the latest shared_ptr.hpp and
detail/shared_count.hpp from the CVS files? The version of shared_ptr in
release 1.30.2 has a lot of extra overhead due to weak_ptr support. Every
time a shared_ptr is copied there is an extra comparison and increment (and
later an extra decrement). The version in the CVS avoids almost all of this
extra work.

Joe Gottman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk