Is there a way to optimize this?

Solution 1:

Technically the answer to your question is "yes, /schedule is more efficient than your scoreboard method". But that won't solve your lag problems, because they are actually caused by light updates.

The bad news: You can't really solve the issue of light updates causing lag. I've experimented with a few different things, like having the roof be transparent and making it night, placing the lamps differently, etc., but it all causes similar amounts of lighting lag.

The good news: You can fake it. Here is a video showcasing a concept that lights up and darkens a long tunnel very quickly without much lag:

The trick: Every change from dark to light is not actually a lighting change, but a change from a darker to a lighter texture from a resource pack. If your flickering is very regular, you can simply do this with an animated texture, that is the best for performance. But if it's less regular, you need to replace the blocks in the tunnel. To make the lighting consistent, you would need a light and a dark variant of all the textures used in your tunnel and change them all. Alternatively, you could also teleport the player between two tunnels, but that might cause slight issues with walking. Experiment with it and check what works best for you.

Here are the two textures I used, I simply replaced the textures of stone and dirt with them and replaced the entire tunnel with the other type using /fill … replace:

             

The left one used the colours #808080 and #FFFFFF, the right one #000000 and #808080. For normal textures, you need an image editor that can increase and decrease the brightness of an image.