Magnesium deficiency is a huge problem in the US. If you're not regularly eating large amounts of leafy greens like spinach, you're probably deficient.
Anything that follows Good Manufacturing Practices should be fine. While there's room for additional optimization, I think you start to experience diminishing returns so it's not worth it for most people.
I’d caveat this — probably anything is fine as long as it’s not Magnesium oxide, which many supplements are. Magnesium oxide is about 30x less bioavailable than essentially all other forms of Magnesium commonly available in supplements.
This is generally true for other minerals as well. The problem is that the oxide form is usually the cheapest and smallest/most dense form of these minerals. This lets them say you’re getting 100% of what you need in one reasonable sized pill. The problem is that over 90% of it goes straight into your poop.
Magnesium oxide is also a laxative so the real bioavailability is ~0% if it's triggering diarrhea. Magnesium (bis)glycinate is good, though it's formed by reacting magnesium oxide with glycine and often has substantial amounts of magnesium oxide remaining in it, so again if it's triggering diarrhea you're not absorbing any of it and need to find a different one.
Anything that follows Good Manufacturing Practices should be fine. While there's room for additional optimization, I think you start to experience diminishing returns so it's not worth it for most people.