Sep 30, 2016

[cppcon2016] c++ Practical Performance Practices -note

Practical Performance Practices

https://github.com/CppCon/CppCon2016/blob/master/Tutorials/Practical%20Performance%20Practices/Practical%20Performance%20Practices%20-%20Jason%20Turner%20-%20CppCon%202016.pdf

Make well-performing code 'by default'

Prefer containers in descendent order:

  • std::array
  • std::vector
  • Then only differ if you need specific behavior.
    Make sure you understand what the library has to do.

 

Always const - Complex Initialization


  • Use IIFE (Immediately-invoked Function Expressions), i.e lambda Expressions.
  • Always Initialize When Const Isn't Practical.
  • Don't Recalculate Values - Calculate on First Use.
  • Branching is slower
  • Atomic is even more slower
  • Calculate At Construction



  • Don't Disable Move Operations / Use Rule of 0
  • Avoid Named Temporaries



  • Avoid object copying
  • Avoid ( shared_ptr ) Copies (use shared_ptr.get())
  • Avoid Automatic Conversions (shared_ptr<Base> <-> shared_ptr<Derived>)
  • Avoid automatic conversions
  • Don't pass smart pointers
  • Make conversion operations explicit
  • Don't use std::endl => '\n' << std::flush


----
Summarize:

  • Avoid shared_ptr
  • Avoid std::endl
  • Always const
  • Always initialize with meaningful values
  • Don't recalculate immutable results


---
Smaller Code Is Faster Code


  • Common code in non-template base class.
  • Prefer return unique_ptr<> from factories
  • Avoid std::function<>
  • Use Lambdas


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.