It may just be that you have unrealistic expectations of what the heater can do for you. If it were the dip tube, you’d have about 15 seconds of hot water and then it would turn tepid.
A 40-gallon heater only has about 26 gallons of hot water. I would check the flow of your showerhead with a stopwatch and bucket. If you don’t have a low-flow head, you maybe should think about getting one.
There might or might not be a heat trap in the nipple on the cold side and it might or might not work. We like passive heat traps made of flex line and insulated. You can see an example in Lingo.