I currently have 86 instances of GetService in my code because I was too lazy to set them as variables at the beginning of my code; Obviously this is horrible practice. But just how bad is it?
It’s probably not that bad. If you’re doing it hundreds of times in an infinite loop it might matter but otherwise its neglible. You might get tired of writing game:GetService though.
I know for a fact some people use a table of services like you suggested, though I would advise against it since it reduces readability.
I doubt it makes a large impact at all, but if you’re worried about the potential impact of :GetService() then you could always log previously indexed services for later use. Though I have no idea if this would be any more efficient.
local Services = setmetatable({},{
__index = function(t,k)
local Service = game:GetService(k)
t[k] = Service
return Service
end
})
Reading this the phrasing seems to suggest caching, so you are just grabbing a reference to an existing service for each subsequent call.
Main purposes seem to be generating non default services and ensuring the acquisition is a service
For services that aren’t around normally you might see some divergence in performance. If say lua GC’s the generated service due to no reference maintained.