What is more optimized: use manually the shader variables or declare it and then use

I’m trying to find out the best way to use the shader variables.

We have some kind of parameters which can be used in the shaders. For example some light parameters:
_WorldSpaceLightPos0 - Directional lights: (world space direction, 0). Other lights: (world space position, 1).

So I have two ways:

half3 lightPos = _WorldSpaceLightPos0.xyz;
o.diff = v.color * max(0, dot(o.worldNormal, lightPos));
o.lightDir = dot(o.worldNormal, normalize(lightPos + o.worldViewDir));
o.diff = v.color * max(0, dot(o.worldNormal, _WorldSpaceLightPos0.xyz));
o.lightDir = dot(o.worldNormal, normalize(_WorldSpaceLightPos0.xyz + o.worldViewDir));

Could you please clarify which one will be more optimized?

They should both compile to the exact same thing. You can check this with Show Generated Code in the Inspector.

This is because the compiler is pretty clever. While some are even better than others, all compilers are expected to handle cases like this by using two memory reads, rather than a read-write, read, read.