Resharper-unity: Expensive math operations as hints

Created on 14 Sep 2015  路  5Comments  路  Source: JetBrains/resharper-unity

Hint that Exp, Sin, Cos, Tan, Sqrt, Pow and even / and % are expensive, especially when inside of the Update method of a MonoBehaviour.

Most helpful comment

I really wouldn't want to be warned about this - it's not like using these operations is an accident that can be corrected.

All 5 comments

Is it a unity thing that makes them expensive? And why especially in a MonoBehaviour?

no, they are just more complex for the cpu and thus take more time than say addition, subtraction or multiplication. If they are in an Update method of a MonoBehaviour we know that they are probably being executed every single frame. If they are in a shader, they might be getting executed for every fragment every frame.

I really wouldn't want to be warned about this - it's not like using these operations is an accident that can be corrected.

Just no, if people know how to use them, they should know the cost. Also generally when resharper or intellij give you hints and inspections, it does so because it is able to correct it for you. So this would go against convention. Also this seems like a slippery slop and inspections and hints are no longer useful if literally everything has as hint.

premature optimization imho.

Was this page helpful?
0 / 5 - 0 ratings