Well you're about to get a plethora of information in this thread that you probably don't care about. And there will be a combination of reasoned information and standard myth and wild speculation coming from all camps. From cap and ball musket is the best to lazer clad super expansion .500 magnum is the only way to go. buckle up.. LOL.
This is my 2 cents. FWIW. When it comes to defense, pistols suck. It's something you have to come to terms with. Pistols are not the ideal defensive system. BUT, no one I know carries a rifle or shotgun every where they go. So we compromise.
True effective difference between the 9mm and .40? Not really. Most information shows that it's going to take between 2 and 3 rounds to stop an attacker and that doesn't even matter what caliber you use. If you talk odds? Well odds are you won't ever need it. If you do, odds are you're facing an unmotivated attacker and even the P22 would stop them. But it's that one in a million event we plan for. In that case, you've got the same odds whether it's a 9mm or a .40 you're carrying.
Some realities. .40 is a higher pressure round and will tend (not always) to wear out parts sooner. But buy sooner I mean like 20,000 rounds instead of 30,000 rounds. So in reality, nothing you'll probably ever care about. .40 tends to be snappier. The recoil is certainly manageable, it's just a sharper impulse curve. That means slightly more muzzle flip. So follow up shots take 2 tenths of a second longer. Or whatever. It's noticeable, but not a deal breaker. 9mm is generally cheaper, which means you can spend more on practice. But if you only plan to shoot like twice a year, that's irrelevant. If you plan to shoot 300 rounds a weak, maybe it would save you some money. (BTW, this is pre-panic pricing. right now on gunbot both are about the same price.) So really, it's like a coin toss.
My only suggestion, choose what you want. Practice, practice, practice. Then practice more and then even more. The caliber is really not important when it boils down to actual defensive use. Having it, carrying it, knowing how to use it. That's what matters.
Side note: I just went to the range with a buddy. He brought his .40 (his only gun) and I brought one of my 9mm (along with some others). After we were done (he shot my 9mm) he said "I should have bought a 9mm." That doesn't mean it's the best or the only way to go. More, if you have a chance, shoot both. You'll either come away not noticing anything different or you'll come away knowing which you want. And don't be afraid of .45. The S&W 45C is a pretty nice option. The actual felt recoil of the .45 is considered to be more comfortable and more controllable than the .40 because it has a longer impulse curve that spreads the force out over a longer time. That makes it feel more like a push than a snap. But that's another can of worms right?