Turning electricity into heat is pretty much 100% efficient, but all the other conversions have outrageous conversion losses. Regardless, using solar is still the best option overall.
However, fossil fuels are still widely used, and that’s where the losses play a significant role. In that context, using gas to heat water is the simplest and most efficient setup. Converting the combustion products into electricity just introduces additional losses, further decreasing the overall efficiency.