I believe that many users of home assistant are building scripts and automations to turn off all lights for bedtime or leaving the home.
Calling the services as of now takes a long time depending on the number of lights.
What I have found is that by only calling the lights that are turned on, the result is instant and a much better experience.
What I am doing right now is using a template, but I think this should just be integrated into the services. There is no reason to turn off a light that is already turned off.
When states is used in a template by itself to iterate all states on the system, the template is re-rendered each time any state changed event happens if any part of the state is accessed. When merely counting states, the template is only re-rendered when a state is added or removed from the system. On busy systems with many entities or hundreds of thousands state changed events per day, templates may re-render more than desirable. From: Rate Limiting Updates