Write that shit down. I know it feels wrong spending the energy and possibly waking yourself up more but you will always remember your genus ideas that your idiot brain rather think about than sleep.
Sleepy brain is weird. I'm a programmer that also writes music. I learned a long time ago that when I write music when I'm half asleep, if I wake myself up and write it down, it's already a song that exists, I just didn't recognize it when I was half asleep. But I can absolutely solve my programming problems while half asleep. I have even solved them in my dreams before. If I get up and write down my idea, or even just my new perspective, I can turn it into code later and it will work (usually).