Can't say I know anything about the the asymptotic efficiency of GetService
, but the obvious thing is that it's guarenteed to be slower than maintaining a reference to the object. At least, this should be obvious, as a reference is just sitting there, waiting to be used, whilst GetService
requires retrieving a Type
instance from a class, then looking up that Type
in whatever collection is used, and finally casting to the correct type, incurring runtime checks and such.
Individually, none of these things is a problem. Even all together, none of them are a problem if only used a few times. But seeing as how you are retrieving these on a per-frame basis, the hit could become apparent, depending on how many services you are retrieving each frame.
Based on the small amount of information I have about your code, I would say that changing to the reference option shouldn't be that hard. But to really decide on whether it's worth it, maybe try to switching to keeping a reference (at least for a couple of services) and checking on how much your FPS changes. Alternatively, throw in some extraneous GetService
calls and see how much of a drop in FPS it causes. That would be a more definitive way to find out the importance of changing everything over.