0

I have read many posts (e.g., this one) saying unique_ptr has no overhead when accessing the content they point to. However, when I run perf record and perf report on my application, I notice the following results:

   - 15.81% lqf::MaskedRowIterator::next                                                                                                                                                                                              ▒
      - 4.92% lqf::SimpleBitmapIterator::next                                                                                                                                                                                        ▒
           _mm_popcnt_u64 (inlined)                                                                                                                                                                                                   ▒
      - 4.88% std::unique_ptr<lqf::BitmapIterator, std::default_delete<lqf::BitmapIterator> >::operator->                                                                                                                             ▒
         - 3.38% std::unique_ptr<lqf::BitmapIterator, std::default_delete<lqf::BitmapIterator> >::get                                                                                                                                 ▒
            - 2.71% std::__uniq_ptr_impl<lqf::BitmapIterator, std::default_delete<lqf::BitmapIterator> >::_M_ptr                                                                                                                      ▒
               - 1.91% std::get<0ul, lqf::BitmapIterator*, std::default_delete<lqf::BitmapIterator> >                                                                                                                                 ▒
                  - 1.13% std::__get_helper<0ul, lqf::BitmapIterator*, std::default_delete<lqf::BitmapIterator> >                                                                                                                     ▒
                       std::_Tuple_impl<0ul, lqf::BitmapIterator*, std::default_delete<lqf::BitmapIterator> >::_M_head                                                                                                                ▒
      - 4.55% std::unique_ptr<lqf::DataRowIterator, std::default_delete<lqf::DataRowIterator> >::operator*                                                                                                                            ▒
         - 3.23% std::unique_ptr<lqf::DataRowIterator, std::default_delete<lqf::DataRowIterator> >::get                                                                                                                               ▒
            - 2.27% std::__uniq_ptr_impl<lqf::DataRowIterator, std::default_delete<lqf::DataRowIterator> >::_M_ptr                                                                                                                    ▒
               - 1.78% std::get<0ul, lqf::DataRowIterator*, std::default_delete<lqf::DataRowIterator> >                                                                                                                               ▒
                  - 1.10% std::__get_helper<0ul, lqf::DataRowIterator*, std::default_delete<lqf::DataRowIterator> >                                                                                                                   ▒
                     - std::_Tuple_impl<0ul, lqf::DataRowIterator*, std::default_delete<lqf::DataRowIterator> >::_M_head                                                                                                              ▒
                          std::_Head_base<0ul, lqf::DataRowIterator*, false>::_M_head                                                                                                                                                 ▒
        0.58% lqf::ParquetRowIterator::operator[]                                                                                                                                                                                     ▒
        0.55% std::unique_ptr<lqf::DataRowIterator, std::default_delete<lqf::DataRowIterator> >::get                                               

In this report, the "*" and "->" operator on a unique_ptr are listed to have non-negligible cost. How should we understand this?

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Harper
  • 1,794
  • 14
  • 31
  • 6
    Did you compile with optimizations turned on? – NathanOliver Mar 12 '20 at 16:19
  • My bad. It seems like the overhead is removed after turning on O3. So the unique_ptr overhead is only removed when turning on optimization? I did not know this before and thanks! – Harper Mar 12 '20 at 16:23
  • 1
    Yeah, without optimizations turned on the compiler is literally going to do all the function calls. With optimizations turned on that can all be compiled away. – NathanOliver Mar 12 '20 at 16:24
  • 2
    Unless you are actually debugging, you always want to turn on optimizations when benchmarking/prfiling. – NathanOliver Mar 12 '20 at 16:26

0 Answers0