Assuming you'd invest this money either way (pay off the loan and invest in the 401(k) or don't pay off the loan and invest in taxable) I suppose it comes down to whether you think your investments will return more than 6% (on average stock investments have returned more in the past) and whether you'd rather have more in taxable or in a tax deferred 401(k).
Think about that one for a second. If you pay 6% interest on a loan you made to yourself, how much are you actually earning?
Answer: Zero! You are making zero percent interest.
And remember, the money goes into the 401(k) pre-tax, but the loan gets paid back post tax. So the actual cost is whatever your effective tax rate is. Probably not zero. So the longer the OP keeps the loan, the more post-tax dollars he needs to cough up in order to pay for the pre-tax dollars he borrowed. I would kill that thing ASAP.
I never said you were actually earning 6%, I said if you believe the money will earn more than 6% invested then you should invest the money in the place you want to have more money, and vice versa.
You can either pay off the loan and invest in the 401(k) or not pay of the loan and invest outside the 401(k). If you want more money inside the 401(k) and less outside the 401(k) then you should pay back the loan if you believe the market will return more than 6% because you will have greater than 6% more inside the 401(k) from investing. If you want less money in the 401(k) and more outside the 401(k) then you should not pay back the loan if you believe the market will return more than 6% because you will have 6% more inside the 401(k) from paying back the loan later and the money outside will grow by more than 6% by being invested. If you believe the market will return less than 6% then you should do the opposite depending on you desired outcome (more/less insider/outside the 401(k)).
All that to say, all else being equal, you won't end up with more money with either option except to the extent that the tax treatment of the money will be different, so it all comes down to where you want more money and whether you think the market will return more or less than the 6% that will end up inside the 401(k) if you pay it back as slowly as you can.
Edit: to your point about pre/post tax dollars, see:
https://thefinancebuff.com/401k-loan-double-taxation-myth.html