Garry's Mod Wiki

Concepts - Optimization Tips

General Tips

Just because something works doesn't mean it cant work faster

  1. Use Local Varibles: local variables are accessed by index instead of hash lookup.
  2. Avoid repeated heap allocations: Creating tables or closures repeatedly can slow down performance.
  3. Prefer inline expressions over function calls: For example: tbl[#tbl + 1] = 0 is faster than table.insert(tbl, 0)
  4. Multiplication Over Division: x * 0.5 is faster than x / 2
  5. Squaring over exponentiation: x * x is faster than x^2
  6. Factor Expressions: x*y + x*z + y*z can become x*(y + z) + y*z