I think one of the reasons is because boost::hold_any uses a template metaprogramming approach whilst boost::any uses an inheritance approach.
Internally, boost::spirit::hold_any stores the "value" using a void* and uses another object to keep track of the data type info:
>> boost/spirit/home/support/detail/hold_any.hpp
template <typename Char>
class basic_hold_any
{
....
spirit::detail::fxn_ptr_table<Char>* table;
void* object;
...
}
boost::any stores the "value" using an holder, and it doesn't need another object to keep track of the data type info. The holder is inherited from placeholder and consequently have the inheritance drawbacks.
>> boost/any.hpp
class any
{
...
placeholder * content;
...
}
class placeholder
template<typename ValueType>
class holder : public placeholder
{
...
ValueType held;
...
}
...the perfomance difference is much more about calling constructors and destructors, but even for casting, boost::spirit::hold_any should be faster.