I've had a lifetime sleep disorder which I've spent the last three decades dissecting. If you have a real disorder, you're getting a lot of well-intentioned yet useless advice about general well being.
So many times in my life I've heard "we all go without sleep, you just learn to deal with it". These are people who can't tell the difference between a nose bleed and haemophilia, because they've never been there.
There are many illnesses which are thought to impact sleep quality. Among these are depression and fibromyalgia. It's not unlikely that depression causes poor sleep, and poor sleep leads to poor memory. Poor sleep alone by another cause is a good depression mimic. A psychologist will understand your symptomatology, but your underlying condition—if it is not actually depression—might not respond to the usual drugs.
On the bright side, some drugs which are considered to be antidepressants actually provide benefits because they directly treat sleep disruption.
Low doses of amitriptyline are commonly used to treat FM. I experienced improved sleep quality, and a boost in initiative and motivation. I also had a fuzzy head for the first half of my day, every day. This wasn't a winning trade off for writing code. This drug (in my body, and by some accounts in the literature) has some kind of weird, antagonistic relationship with caffeine. By the time I consumed enough caffeine to clear the fuzzy brain, I lost all the sleep benefits.
Most people way overdose with caffeine. Once you start chasing the tolerance effect (tolerance begins in as little as a week or two in novice coffee drinkers) you end up drinking about three times as much as you need to get a small increase in net buzz. All that extra caffeine in your body is not friendly to your adrenal system, and it's known to mildly disturb your sleep architecture. The nose-bleeders can ignore this term, if they wish. We sleep haemophiliacs can't afford to play marbles in a rose bush.
I get 80% of the benefit from caffeine drinking two cups a day, with 7-8 g of ground coffee and 120 g of water per cup. I drink one immediately on waking, and the second cup six hours later (four to seven hours is an acceptable range). This is half what I was drinking the first time I thought I'd achieved moderation. Don't ask me about my pre-moderation coffee consumption. I've learned that it takes my body about three weeks to accept a coffee reduction of 30% as being perfectly normal. The key is to use a gram scale, because for the first ten days your brain is working overtime on how to cheat the system. Never drink a coffee you don't make yourself while cutting back: you'll feel glorious and your brain won't let you forget it.
Half of an amitriptyline dose metabolises into an equally cheap drug, nortriptyline. Weirdly, both sides of the AT metabolism are active. When I discovered this, I thought "why don't I just try the NT half by itself". This was a good call: almost as much sleep benefit, way less fuzzy brain.
I get a condition I call "clutch slip" where the cognitive side of my mind is well aware of all things I need to be doing, but I completely lack some mysterious edge to dive into these tasks and do them. The nose-bleed assholes are going to fuck this up again. Yes, I can actually force myself to grin and bear it and do the work. No, applying the lash does not get me past this clutch-slip psychological barrier to the promised land of actually becoming absorbed in the work. If only. I'd pray for that to happen, even at the risk of being socially rejected by all my heroes in the afterlife we all vehemently reject. Worse, the caliber of my work is shit warmed over. In other words, what passes in this life as mediocrity.
Have you ever had the experience where you're in some life or death struggle with a complex regex or an XSLT script to sanitize an input file and suddenly you realize, "you know, I could run this through tools A, B, C, and D then the simple version of this thing I had half an hour ago would actually be sufficient"? In a month of toiling under the lash in the clutch-slip state of being this would never happen for me. The entire mental process of relating what you are doing to where you are going and what you could be doing instead to get there sooner or in a better way is dead in the water. That really makes the lash sting. When I'm trapped in that world of self-flagellation, outside-the-box ceases to function. Furthermore, it's morally exhausting. After about a month of this, you fundamentally don't give a shit. All you've got left is the dull roar of obligation. "Why am I doing this?" you ask yourself. "I can't remember." you answer back. "Is there another way?" you dare to dream. "Sleep" you answer back. If I could just sleep.
It used to be that one dose of NT before bed time when I felt this way would knock me out for twelve hours, then I would wake up a new man, and "the box" would unfold its wings. There are at least three different NT generics, and at least one of those causes me stomach cramps severe enough to interrupt the sleep I'm taking the drug to achieve. I also suspect that its potency slowly fades sitting in the bathroom pill cabinet. At this point I take it only about twice a month. Recently it's been taking two pills (20 mg total) to knock me out for just a decent eight hours. That bottle is very old now. Also, NT works far less well for me when I'm drinking too much coffee.
This past year I've been taking an anti-narcoleptic nootropic, a drug that must not be named because it gives a genital tingle to over-stressed college students. This drug is not a sex toy.
I don't suffer narcolepsy, but I do suffer from these recurrent episodes of clutch slip (I can pencil them into my calendar months in advance, since they derive from a circadian rhythm disorder that beats regular time like a metronome from another planet). If I take half of the smallest available pill (in Canada, that works out to 50 mg) most of my clutch-slip goes away. It's almost miraculous. For the first few months, it also had a mildly euphoric edge, making the most tedious task trivial to engage for hours and hours. After a month or two, that vanished completely. It was a double-edged sword to begin with, because with an infinite tolerance for monotony you might spend an entire 12-hour night tweaking your .emacs—on a weekly basis. I take a bit extra as needed as my body slides into night mode and my clutch begins to glass over.
There's a huge problem with this which I've yet to resolve. The drug reduces my total sleep capacity. By the end of night mode, I'm lucky to get a solid five hour sleep. My brain is still cranking out the horsepower, but the gas gauge is reading "empty". I get so sleep deprived that I often experience a 24-hour day where I'm in and out of bed every few hours, never achieving more than half a cat nap, but at least getting myself back to 1/4 of a tank.
Another drug worth trying is clonadine. This messes with your blood pressure, so you need to be fairly desperate to go this route. It somehow changes your sleep architecture. According to the sleep literature, small doses affect your sleep architecture in a different direction than large doses. Weird, huh? You'll need to find an absolutely first rate sleep doctor if you expect your doctor to have command of these niceties.
On that score, the first thing you need to realize is that 90% of sleep doctors are glorified respirologists. If they answer isn't either A) a CPAP machine, or B) bland imprecations concerning your sleep hygiene, these doctors can't help you. No, I'm not bitter. Seriously, most of the time you'd be better off with a GP who specializes in CF or FM.
I took a few doses, small and large. It had no immediate positive effect, so I shelved it for the time being. I'm not going to take a drug that puts me at risk of randomly passing out and cracking my head open on a side walk unless it makes a great first impression.
Another problem with my nootropic is that it suppresses the yawn signal, so I can end up not sleeping at the right times. If you don't sleep at the right time (according to your inner circadian clock) you don't go through the sleep phases in the same way. It will restore your energy in the short term, and then put you into a state of hideous sleep deprivation by the end of a week (e.g. many hours sawing logs in the sack, but zero REM sleep for the duration).
Yes, and good luck managing all these options, upsides and downsides, while you're the guinea pig a sleep-quality experiment that spends much of the time going sideways. That always leads to excellent judgment. Take notes. Read your notes whenever your saner self makes a surprise appearance. Document every pill you take. Make a medication plan at the beginning of the day or week. Never let your inner 04:00 infomercial shopper make medication adjustments on the fly. The first element of sleep-deprived judgment that goes away is your ability to accurately gauge your level of impairment. When I mention this to doctors, there's always this sudden knowing look (they're thinking about their colleagues) and a facial expression "ain't that the fucking truth". The peril of making an unnoticed descent into poor judgement is the one term of sleep impairment that most GPs immediately get at the gut level.
It sure looks a lot easier to grapple with the lion from up in the nosebleed seats. "What's your problem, anyway? I suffer, too, when the alarm goes off!" Ignore these bastards. They have no clue.