I'm on my fourth iPhone in 13 years and have never replaced a phone because of anything related to physical damage. I'd still be on my third but T-Mobile offered such a large trade-in value for my 2020 SE that upgrading was the same price as replacing the battery.
The issue with batteries on older iPhones isn't even replacing the battery. Apple will do it for like $80 bucks or so out of warranty. That's WAY cheaper than a new phone.
But every new OS version manages to use more CPU and GPU and burn down that battery faster even if it's brand new, since the older chips have to work harder to run them than they had to work to run the older OSes.
I replaced my battery which was showing around 83% of original capacity last year, in a 3-4 year old phone. I was skeptical of the 83% reported number. Nope. The new battery didn't last much longer, nowhere close to how long it lasted on the OS it shipped with.
(This software-cpu-bloat is not unique to Apple. My Pixel, after 4 years or so, was practically unusable just from the amount of background shit the CPU was doing, compared to when it was new.)
Yes software bloat and lack of optimisation is the problem.
But this is exactly why Apple is full of shit. They pretend to do and know better by forcing updates and locking down your ability to install/manage software as you see fit; yet you do not get any meaningful value in exchange.
All the App Store discourse would be moot if they clearly enforced a minimum software quality but they are way too greedy to actually do that.
So in the end you are subjected to the same software bloat as Android but you just pay more for the device.
Pixels get slow because they have very weak CPUs to begin with. If you had gone with a Samsung the experience would be much better (not too different than that of an iPhone, even though the look is of a different taste).