I don't think anybody can answer this question for you. At 40, you can still do the exact same jobs as someone who's 25 (at least in tech) if you put your heart in it. I don't know what's the expiry date for a SWE, but it's not 40. I'm a median IC in big tech at almost 50 and don't feel discriminated against yet, and for the most part, don't feel incompetent or behind, and feel I'm having the greatest time of my care…
While many people talk about a bias against hiring ICs over 40 I also wonder if there is a bias to favor people over 40 for promotions.
* They tend to get stuck on old technologies that nobody uses any more. I don't really care about your Perl skills, sorry.
* They expect higher salaries.
If you keep up to date with your skills (Rust, Typescript, Nix, etc.) and aren't precious about your salary increasing forever then I don't think there's an issue. I've worked with plenty of very skilled ICs into their 60s.