There is no correct length, only what works for you on the trails you ride on that specific bike. Just buy a few cheap Brand X stems from CRC and play around.
Also, buy a decent tyre pressure gauge. Write down your tyre pressures and experiment a bit.
Also, tyres do wear and if you’ve been riding the same front tyre for six months, it won’t be as grippy as when it was new. Trying different tyres is another obvious thing. Ask around and see what people use for the trails you ride. A tyre that is brilliant on dry hardpack will probably suck on wet roots.
Also, weather can make huge differences to trails. Your tyres will wash out if you push hard on wet leaves, but the same trail can be incredibly grippy a few days later once it dries out. Soft trails are sometimes the opposite – too dry and your tyres wash out, a bit of rain and they suddenly get really grippy, but too much rain and they turn to mud.