Concepts - Optimization Tips
General Tips
Just because something works doesn't mean it cant work faster
- Use Local Varibles: local variables are accessed by index instead of hash lookup.
- Avoid repeated heap allocations: Creating tables or closures repeatedly can slow down performance.
- Prefer inline expressions over function calls: For example:
tbl[#tbl + 1] = 0
is faster than table.insert(tbl, 0) - Multiplication Over Division:
x * 0.5
is faster thanx / 2
- Squaring over exponentiation:
x * x
is faster thanx^2
- Factor Expressions:
x*y + x*z + y*z
can becomex*(y + z) + y*z