Yeah, that's the bottom line.
When student loans were 2.x% and mortgages were 2.x or 3.x%, of course there are better investments... and no real payoff urgency to pay debts. That is why you see many older DPMs living large yet still making minimal pays on student loans: they had most/all fixed low interest rates (some 1.x%).
Now, with 7.x% loans and variable potentially even higher, payoff is a real good return. Not very many DPMs have Pslf jobs or IHS that will pay or forgive balances... so, the choices for 95% of podiatrists are payoff or try for 20 or 25yr forgiveness.
Personally, when student loans were low rate, I was paying minimums or slightly more (I had a mix of 2.x% and 6.x%), and I did investing and saving a bit. My income was low, but it worked out to have $ to start a PP later without adding debt.
Since student loan are now 7.x% on all of my remaining student loans, there is almost no way to beat that. Even though my income is higher and I could mask it to lower monthly payments, interest would crush me. I just created healthy biz and personal savings, now do the "boring" roughly triple payments on the standard student loan repayment rate. Most PP owners I know did the same.
Although I still buy them monthly, index funds and most single stocks have basically gone sideways. I have picked some good ones like NVO and LLY and outpaced the S&P, but index SPY and QQQ are still my major buys with returns pale in comparison to paying my loans in the past few years. My partner is doing same on 4.x% "15 year" mortgage we live in: doing a bit of investing, but mainly knocking out the house loan in the next couple years, as opposed to paying hundreds of thousands in additional interest (it was the opposite on her prior 2.x% house years ago... still paid it off early in less than 10yrs, but mainly did market investments in that rate climate).
The bottom line is that there are no always/never answers, but present day loans rates are very high with markets pretty unimpressive. Even if hoping for improvement in the markets, historical index S&P average returns are 7 or 8% avg
not guaranteed... but loan payoff is now 7.x%
guaranteed. It's never unwise to take a good guaranteed return rate.