I find myself consistently productive over long spans without a burnout effect when I am sleeping at consistent hours, and working for consistent hours a day. When I overwork my productivity becomes inconsistent so I stopped doing that. I learnt it the hard way that late night coding is a short-term investment with negative return in the long run.
My personal theory is that our brains like consistency and adapt/tune to it over time. Just like when you jog every day, if you run for too long one day and too short the other day it cannot adapt/tune itself to a semi-random pattern.