There is a lot of miss information on gear selection and cadence for mountain biking and I would like to clear some things up for you.
As for cadence we are mountain biking, not road riding! This means we have a lot more variables to deal with (than road riders), roots, rocks, loose conditions, etc often requiring us to use a slow cadence to maintain traction and balance. While Lance Armstrong popularized the idea of spinning an easy gear I have never seen a study that proves this is the most economical way to climb for all body types and it can be every hard to maintain control on trail why spinning a high rpm. Many of the best mountain bikers (Tinker Juarez comes to mind) and even some road racers (Jan Ullrich) push really hard gears. So use a cadence that is comfortable for you, taking into account your fitness, power to weight ratio, traction and balance demands.
Always while riding adjust your gearing to the speed you are going!
When going from a downhill to uphill do not shift into an easier gear before necessary as you will lose precious momentum while coasting (unable to pedal) uphill and often lose your balance (by pedaling with no resistance throwing your weight forward). This means if you are in your hardest gear at the bottom of a hill stay in that gear as you start climbing to keep your momentum up! Then, shift as needed (do not shift under power, do a “soft pedal” (a full revolution with no power to the rear wheel) when shifting on a climb) maintaining your momentum! By only shifting when needed you can often maintain a much higher pace while using less energy on a climb (see previous article on going faster with less energy).
To accelerate a bike we need to be an an easy gear, not a gear we are straining to push. As you are slowing to enter a corner (where you will be coasting through) shift into a gear to match your speed on the exit of the corner (this takes some practice to learn what gear feels good at what speed).
Power modulation is also important! Sudden surges in power can cause wheel spin (wasting energy and possibly loosing balance/control) while climbing as can just plain applying too much power for the conditions. I often see super powerful riders crank uphills at speeds I am envious of but I can hear their rear slipping, if they backed off on power just a little bit they would climb just as fast or faster using less energy! Have you ever spun out on slippery root while climbing? Next time trying slowly increasing your power for a pedal stroke or three before the root then doing a “soft pedal” over the root and getting back on the power once passed the root. In short, producing a lot of power is great but relying on power instead of finesse wastes energy and often causes you to stall or crash.