Okay, so I'm warming up my patented 'Myoclonic Professor' cap here... I've researched it to hell and back because I have a moment to moment, daily struggle with them and have for 10 years...
Now, do you have epilepsy? Do you have tonic clonic (grand mal) seizures? Absence seizures (staring spells)? Do you do odd actions or talk strangely? (partial or complex seizures...)
The reason I ask is because while there is a cornacopia of afflictions and syndromes of which myoclonus is a symptom of(and it is diagnosed as a symptom, not a problem in and of itself...), primarily it's attatched to two very distinct disorders... Juvenile or Progressive Myoclonic Epilepsies... and Myoclonic Dystonia (a sort of cousin to epilepsy, it too is a movement disorder probably more akin to something like Parkinson's Disease...)
I'm not as well read up on Dystonia but I know all about myoclonus in general...
Right before you fall asleep is actually not considered a myoclonic jerk... that would be considered a 'hypnic jerk', and those ones are perfectly normal, almost everyone gets them.
There are different forms of 'myoclonus' though -
http://www.ninds.nih.gov/disorders/myoclonus/detail_myoclonus.htm#261133160
That website has lots of good info but I'll encapsulate the types here...
Action myoclonus is characterized by muscular jerking triggered or intensified by voluntary movement or even the intention to move. It may be made worse by attempts at precise, coordinated movements. Action myoclonus is the most disabling form of myoclonus and can affect the arms, legs, face, and even the voice. This type of myoclonus often is caused by brain damage that results from a lack of oxygen and blood flow to the brain when breathing or heartbeat is temporarily stopped.
Cortical reflex myoclonus is thought to be a type of epilepsy that originates in the cerebral cortex - the outer layer, or "gray matter," of the brain, responsible for much of the information processing that takes place in the brain. In this type of myoclonus, jerks usually involve only a few muscles in one part of the body, but jerks involving many muscles also may occur. Cortical reflex myoclonus can be intensified when individuals attempt to move in a certain way (action myoclonus) or perceive a particular sensation.
Essential myoclonus occurs in the absence of epilepsy or other apparent abnormalities in the brain or nerves. It can occur randomly in people with no family history, but it also can appear among members of the same family, indicating that it sometimes may be an inherited disorder. Essential myoclonus tends to be stable without increasing in severity over time. In some families, there is an association of essential myoclonus, essential tremor, and even a form of dystonia, called myoclonus dystonia. Another form of essential myoclonus may be a type of epilepsy with no known cause.
Palatal myoclonus is a regular, rhythmic contraction of one or both sides of the rear of the roof of the mouth, called the soft palate. These contractions may be accompanied by myoclonus in other muscles, including those in the face, tongue, throat, and diaphragm. The contractions are very rapid, occurring as often as 150 times a minute, and may persist during sleep. The condition usually appears in adults and can last indefinitely. Some people with palatal myoclonus regard it as a minor problem, although some occasionally complain of a "clicking" sound in the ear, a noise made as the muscles in the soft palate contract. The disorder can cause discomfort and severe pain in some individuals.
Progressive myoclonus epilepsy (PME) is a group of diseases characterized by myoclonus, epileptic seizures, and other serious symptoms such as trouble walking or speaking. These rare disorders often get worse over time and sometimes are fatal. Studies have identified many forms of PME. Lafora body disease is inherited as an autosomal recessive disorder, meaning that the disease occurs only when a child inherits two copies of a defective gene, one from each parent. Lafora body disease is characterized by myoclonus, epileptic seizures, and dementia (progressive loss of memory and other intellectual functions). A second group of PME diseases belonging to the class of cerebral storage diseases usually involves myoclonus, visual problems, dementia, and dystonia (sustained muscle contractions that cause twisting movements or abnormal postures). Another group of PME disorders in the class of system degenerations often is accompanied by action myoclonus, seizures, and problems with balance and walking. Many of these PME diseases begin in childhood or adolescence.
Reticular reflex myoclonus is thought to be a type of generalized epilepsy that originates in the brain stem, the part of the brain that connects to the spinal cord and controls vital functions such as breathing and heartbeat. Myoclonic jerks usually affect the whole body, with muscles on both sides of the body affected simultaneously. In some people, myoclonic jerks occur in only a part of the body, such as the legs, with all the muscles in that part being involved in each jerk. Reticular reflex myoclonus can be triggered by either a voluntary movement or an external stimulus.
Stimulus-sensitive myoclonus is triggered by a variety of external events, including noise, movement, and light. Surprise may increase the sensitivity of the individual.
Sleep myoclonus occurs during the initial phases of sleep, especially at the moment of dropping off to sleep. Some forms appear to be stimulus-sensitive. Some persons with sleep myoclonus are rarely troubled by, or need treatment for, the condition. However, myoclonus may be a symptom in more complex and disturbing sleep disorders, such as restless legs syndrome, and may require treatment by a doctor.
Okay... now that we have an outlier of the types of myoclonus, I'll work on the assumption you've had some epilepsy activity... hence being on this forum... and I have some tips.
If you're up until 3 A.M., I'm assuming you don't get a lot of sleep... if you have JME(which is probably the odds-on favorite in this case...), that's the worst thing in the world and may cause TCs... it also worsens the myoclonic jerks themselves... if you have myoclonic jerks... there's no ifs ands or buts, about it...
YOU HAVE TO GET 8 HOURS OF SLEEP EVERY SINGLE NIGHT NO MATTER WHAT.
Moving onward... 5HTP and Magnesium supplements are some things that are sworn by some but I've received medical advice stating they have very little effect and are very taxing on the body with a long kick-in time... also certain diets have been known to help myoclonus but I'm not an avid fan of dietary curbing because it can become so complicated, adhering to it is really untenable...
My best advice is this... you have to get drugs. That means finding a way to a Doctor... if you're in Europe, you need to get something called Piracetam... it's not permitted in the US but there's a synthetic clone of it nearly called Keppra... it works WONDERS on the jerks...
As a short-term rescuer, I would use Ativan to help calm nerves but I also strongly advice using a low-dose Benzoadepine such as Valium or the family thereilk of, to overall slow down the central nervous system... because it being overactive is what is physically causing the jerks... you're a nervous mess, essentially lol.
Another tip if you're having SERIOUS proglems with the jerks, if they're clustering... and you have no access to a Doctor... GRAB SOME BEER. This is a costly quick fix because it taxes your brain and there will be serious repercussions in the morning because it'll smash down your seizure threshold and myoclonus threshold but if it's an emergency and you're having trouble functioning... it's better then the alternative... so, if in case of emergency, break glass kind of poor man's alternative... get drunk. Just make sure the next day you can completely chill and mellow out 'cuz you'll be of no use to anyone...
Clobazam has been used off-label to treat it as well but it doesn't have good reviews... Lamictal will enhance the jerks... Valproaic acid can as well even though that AED is actually the favorite to treat Myoclonic Epilepsy, so it's a double edged sword...
But in all reality, you need to learn to 'relax' and chill out and tax your mind the least in order to reduce the jerks... only way to see a real difference is to get drugs from a doctor (or other source if you have the know-how, I don't judge...lol)
In your case though.. GET SOME SLEEP.