Boost logo

Boost Users :

Subject: Re: [Boost-users] Flyweight: wrapping shared_ptr
From: Akim Demaille (akim_at_[hidden])
Date: 2014-10-22 09:34:23


Hi Joaquin!

Le 14 oct. 2014 à 11:34, Joaquin M Lopez Munoz <joaquin_at_[hidden]> a écrit :

>>>> ./1 0,02s user 0,00s system 93% cpu 0,031 total
>>>> ./7 0,06s user 0,00s system 97% cpu 0,070 total
>>>> ./9 46,19s user 0,09s system 99% cpu 46,424 total
>>>> ./10 171,29s user 9,71s system 99% cpu 3:01,09 total
>>>> ./11 17,25s user 0,04s system 99% cpu 17,296 total
>>>>
>>>
>>> Well, seems like there's a clear winner here (ruling out #1, which
>>> I understand from what you say it's not an acceptable alternative,
>>> presumably because of memory limitations).
>>
>> No, my hope is that I can get faster hashing and operator== on
>> my expressions in all the algorithms that are on top of these
>> expressions. I am not yet worried about memory consumption.
>> But maybe I'm hoping for something I won't get...
>
> Hashing and equality comparison of flyweight'd expressions is going
> to be blazingly fast as compared with recursive non-flyweight'd
> versions.

Yes, that's where I expect to get most of my speed up. However,
for deep expressions, ordered containers were quite fast, more
than hashes, since often the comparison does not go deep inside.
So I'll have to bench whether to stick to ordered containers, or
move to unordered ones.

> Also, have you considered memoizing eval(), either by
> storing eval result in the expressions themselves or using something
> like the following?

On this regard, I don't like Boost.Flyweight too much, and
prefer to cache myself. Using an unordered_map for instance,
in a functor, make memory-management cheap and easy. AFAICT,
there is nothing comparable with Flyweight: either I pay a useless
ref-counting, or I leak, right?

I prefer a map that storing the result in the expression, because
in my case (rational expressions, sort of generalized regular
expressions if you wish) there are many (deep) algorithms for which
I'd like to get such a cache.

However a friend of mine, for a similar set-up, implemented his own
flyweight, and uses it to store a (unique) number in the formulas.
So it's even better than hashing, as he can use plain vectors for
his caches.

I've not deployed this in my project yet, so I can't provide figures.
I expect I'll be able to be back on this topic in a couple of weeks
or so.

Cheers!


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net