DEV Community

Discussion on: How Have You Refractored or Optimized Code for Improved Performance?

Collapse
 
sjmulder profile image
Sijmen J. Mulder • Edited
  • Use a profiler
  • Do less work
    • Simplify and cut out the cruft. Avoid unnecessary abstractions or steps.
    • Don't repeat work (e.g. duplicate database queries)
    • Don't ask more than needed (DB queries are again a good example)
    • Preprocess what you can, e.g. take work out of the hot loop and do it once it advance, create lookup tables, etc.
  • Make the work faster
    • Lay out your data in a way that's convenient for the processing (data-oriented programming). Array in, loop, array out tends to play well with how CPUs and memory work.
    • Avoid indirection. That's pointers, virtual methods, string matching, etc.