Three tips come to mind:
1. Get enough sleep. You've only written three paragraphs and there are already a lot of suggestions that you need more ("I don't feel as productive as others", "I just drop dead in bed" when well-rested people usually take 15-30 to fall asleep, "I felt like I was inches away from becoming part of the zombie horde.")
Coding pretty intensively uses your short-term memory: "I need to take this query which I prepared above and execute it on those variables, wait, this key from the database gets renamed to that on the front-end, okay, test it... dictionary does not have the right key on line 189? What's over there? Oh, I forgot to do this critical preprocessing step, jump back to my code, 3 lines before, add the function call, test again -- what the crap is that, switch back to editor, aha, missed a semicolon here...". Each of those actions requires you to not be overwhelmed by the number of details you have to remember, whether it's where your tool for testing is located, or what the preprocessing function was called, or what have you.
When you're even a little sleep-deprived, your short-term memory decreases dramatically -- if most normal humans can only juggle 7 balls (7 big details or crucial tasks occupying their memory), missing a few hours of sleep brings it down to 4 or 3. So of course everything looks two times bigger.
Sleep deprivation also causes you to lean on substances like sugar and caffeine, and those substances tend to cause procrastination "I'll browse Reddit until this kicks in" -- until their effects wear off and leave you right back where you started with a bunch of nothing done. You can mitigate this somewhat by giving yourself a short task to do before the caffeine kicks in, even if it's an asinine one like "write down what you want to do today." Speaking of the which...
2. Write shit down, set alarms, otherwise use harebrained tools.
Those 7 balls that you can juggle need to incorporate just about everything that is happening in both personal and professional life -- not just code. If those things are in the mix, then you're not as effective. Just like how you should set an alarm for "time to start brushing my teeth and getting ready to go to bed" so that you can get enough sleep, you can set an alarm for "at this time I need to stop everything and call the couch company to send someone to fix the couch at home." Write those things down somewhere, set an alarm to look at that list and do the things on it.
3. Kill context-switches. Either lie your ass off about them or say "no" up front or be honest -- whatever is necessary to kill them.
Take your hands, open them in front of you, spread out your fingers, interleave them. That is 8 work tasks spread out over some distance L. Maybe it's 8 hours of the day working on two projects, Right and Left. One gets concluded at 4pm, the other at 5pm. We'll assume you got started at 8am and ignore an hour for lunch.
Now separate your hands and collapse your fingers. Put your right hand above your left hand, touching. Still 8 fingers in a row, but now you notice that your Left project is released at 12pm before lunch, while your Right project is still released at 5pm after. You just improved your average time-to-completion by 2 hours with no stress, and no improvement in efficiency: you just rushed one project out, then focused on the other.
Now interleave your fingers again and remember how each of those switches between projects feels. You've got 7 in there, yes? Each one doesn't feel good, does it? Because you've got to stop juggling one set of balls, put it all down, and slowly start juggling this other set of balls. Each context switch eats up mental energy. (It also eats up time -- if you need 15 minutes to really get up to speed, then the 7 context switches eat up almost 2 extra hours of your day. So there is an undisclosed efficiency gain here.)
If management forces on you to be working on the two things at once with constant status updates, strongly consider lying your butt off. (Of course, first show your boss the trick with the fingers, it usually convinces them.) Because if management is asking you to do worse work slower so that they can be polite to two of their separate clients, then management has failed. They're supposed to buffer you from all of that crap.
If you can't lie and you can't convince your management, try a firm "no." Just say "I'm on this high-stakes Project Left right now, I can't take on Project Right right now, maybe when Project Left is over I can. Fortunately I think Project Left will be done by end-of-day today, possibly before, so if you really can't find someone else, I may be able to start Project Right today." A "no" always goes better with a nice timetable that suggests that the task will still get accomplished in a timely manner.
Similarly, ignore those "trends" when you're coding. Trends are another project with another context switch. Don't interleave it with anything else.