I'm around 40 and recently I have been asked to port an API from one language to another. The code I'm porting is average code, not terrible, but plenty of little things to complain about.
I feel like my past self could have handled this task, but I am really struggling. Porting this API will require a deep understanding of the existing API, which, of course, has several layers of abstraction.
I can't seem to hold more than about 2 levels of call stack in my head. There's the entry point function which calls other functions, which call other functions, which call other functions, etc. You know how it is, code calls other code, and logically it forms a tree of calls and return values that often goes several layers deep. I struggle to hold more than about 2 levels of this call stack in my head. By the time I'm down in the weeds I've forgotten what I'm doing, what the purpose of the actual API call is.
I don't know how to break this into small enough chunks that I can understand it or make progress on. Imagine I gave you the code for the sha512 algorithm, and a hash, and asked you to find the pre-image (the input). This is how I feel. Where do I even get started? How do I find even a single chunk of manageable work to break off.
The hard part is, several other developers are making progress on porting this API. Why can't I? What happened?
I don't know if this task is just an especially bad fit for me, or if my mental abilities are declining?
As we age, we usually end up with more and more life responsibilities, beyond just the work we are doing. All of that is input to the brain and requires energy in response. The brain is not infinite.
I often feel as you do, but then I have periods where I am as light and agile in my productivity as 20 years ago, maybe even more so, and usually it is my life circumstances that are the culprit.
I remember once about 13 years ago I was working on a mobile game and had a similar problem as you describe; there was one day where the technical work seemed to overwhelm me and I felt inadequate. But I was just a young chap, and it was a passing moment -- I had indeed just taken on some enormous new life responsibilities at that time, which were the likely explanation.
Burnout is real, too, and giving yourself space (if you can) to relax and not think about work for a break can be quite useful to recharge.