I’m learning unity(as well as programming) for 6 months. Recently I’ve discovered Casey Muratory’s “Clean code, terrible performance”. After a while, I understood, that type casting in polymorphism is main issue why this may damage performance. However, there’s a couple of questions, which I simply can’t find an answer across the internet:
1.As I know, C# itself is using polymorphism(interfaces especially as I know) almost everywhere. Doesn’t it significantly damages its performance? Where can I read more about it?
2.Does Unity itself use a lot of polymorphism under the hood? Isn’t it an issue? Just imagine that unity is 25 times faster than now…
3.Unity highly recommends using all of these Inheritance and Interfaces(as I understand), which means that Polymorphism and type casting involved. Why? How could I know, where it damages performance and where not?
4.I used unity profiler to check performance of my code. I have 10k objects in a hashset. They are non-mono-behaviour, but a separate c# class, even not derived from something. They have some function, what they’re doing is adding deltatime to float, so waiting 5 seconds and then doing some calculations and if checks. All of them are managed by MonoBehaviour script - 10k times every update. So, when these objects are pure c# class, this manager’s update takes 1.2ms(worst case), but if Manager handles them as Interfaces(so type casting involved as I understand), I get the same 1.2ms(in worst case), and I can’t even say if regular case isn’t the exact same. So, what am I missing? Should I use different profiler to get better data or I simply got mad?
And after all,
5.Assuming that all these stuff doesn’t damage neither c# performance, nor Unity’s one, nor even my own in my project, do I even have to care about how should I use OOP?
I’m really sorry if any of these questions look some kind of stupid. I was really impressed by 25 times performance increased by Casey, and would like to know how should I use these new cool concept that I’ve learned by him.
Thanks!