Subject: Re: [boost] [MPL][vector] Is there interest in mpl::vector using variadic templates?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2017-03-03 13:46:13
On 03/02/2017 01:54 PM, Bruno Dutra via Boost wrote:
> On Thu, Mar 2, 2017 at 7:42 PM, Larry Evans via Boost <boost_at_[hidden]
>> On 03/02/2017 11:54 AM, Larry Evans via Boost wrote:
>>> On 03/02/2017 11:27 AM, Peter Dimov via Boost wrote:
>>>> Larry Evans wrote:
>>>> One problem with the above cppljevans mpl is there's no at.hpp.
>>>>> Instead, the non-variadic boost/mpl/at.hpp was used.
>>>>> The reason no variadic at was created was because, AFAICT, there was
>>>>> no non-recursive method for picking the I-th element from T... , and,
>>>>> IIUC, recursive templates cause compile-time slow downs.
>>>> Have you read
>>> Nope. Thanks *very much* for the link. I'm impressed (especially
>>> with the way you actually cited the parts of the standard to guide
>>> your search for the best method!).
>>>> Search for mp_at.
>>>> Thanks for that tip.
>>> I'm a bit surprised that the mp_map_from_list was fastest.
>>> I would have thought that large template classes mean slow
>>> compile times, but I guess not.
> Since you seem to be interested on benchmarking compilation times, check
> out http://metaben.ch.
The at benchmark there indicates mpl.vector is the fastest
in the, I guess you'd call it, the "performance at given
number_of_elements pop-up list", when the cursor is moved
over to the rhs at number_of_elements=500. Hmmm. Now I see
there's actually no mpl.vector graph at that
number_of_elements. OOPS. I see that that's because
mpl.vector was not run for number_of_elements > 50, but
that's only obvious when the subtract_baseline radio button
is turned-off. To avoid this confusion, the graph should
give some indication, in the "performance at given
number_of_elements pop-up list", which methods were actually
run at the given number_of_elements.
>> template instantiations use memory that is never freed during the
>> compilation process
>> so, maybe mp_map_from_list should be used with caution. If many
>> mp_map_from_list instantiations are used, I'm guessing the compiler
>> might become pressed for memory. Maybe a benchmark showing
>> compile time vs number of instantiations would show this.
>> For example, instead of N=800, see what happens when 2
>> instantiations with N=400 happen, and compare with a similar
>> test for mp_repeat_c.
> This is actually not the case, in fact the exact opposite is true.
So n4235.htm was wrong or maybe I've misinterpreted it?
> It turns
> out mp_map_from_list is actually very cheap to the compiler in terms of
> memory allocation, because it takes advantage of template memoization, so
> if you retrieve every single element of a list using this trick, the
> compiler needs to instantiate it only once. On the other hand, the trick
> employing void pointers can't be expressed in a way that take advantage of
> memoization, which means that, for every element retrieved from the list,
> the entire pack of void pointers must be instantiated again.
So how do you resolve what n4235 is saying and what you say above?
I'm guessing that 4235 was actually referring to this
memoization when it said:
template instantiations use memory that is never freed
The memoizations do use memory which, IIUC, is never freed
until the compiler is finished. OTOH, when you say:
> for every element retrieved from the list, the entire pack
> of void pointers must be instantiated again.
That means more compile time is needed for the repeated
instantiations; however, no memory is *permanently* used as
is the case for memoization. IOW, this is a classic case of
trading memory for speed:
OTOH, my point was that as these memoization's increase, the
compiler has less memory to use; hence, might slow down;
whereas, since, the memory used by the vec_of_void* method
is reused, memory pressure is less, and, although it's
slower for 1 instance of a pack, it might become faster as
many packs are used.
I hope that makes more sense ;)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk