So I’ve done this a few times, and I see some decent pointers in this thread, but also some misleading assumptions. For example, this isn’t a simple interest rate A to interest rate B comparison because with a 401K loan, you’re paying yourself back. Not a bank. Second, yes... you’ll likely miss out on some market growth by pulling out of your 401K, but not for the full period. As soon as you finalize the loan, you’ll be making payments immediately back into your 401K which will complement normal contributions and grow just like them.
I don’t know what kind of interest rates, loan periods, etc we’re talking here, but I do know that 401K loans tend to be capped at 60-84 months. My gut tells me that your absolute best all-around financial option would be to simply make extra payments on your HELOC so that it can be paid in full in 5 years, thus avoiding a decent chunk of interest. That said, we’re probably splitting hairs by the time it’s all said and done, and like another poster said... we’re all acting like the market is gonna continue to surge. If it doesn’t, you could come out great by taking a 401K loan.
Only advice I have is go with the route that helps you sleep better at night, BUT know that there’s typically a $50K or similar cap to total 401K loans that can be pulled out, so I try to be real careful to only use it when it makes rock solid sense. You just never know when an emergency might pop up