Right after bonus season is the correct answer. :D
What is this mystical "bonus season" you all keep talking about? I've never had a bonus in my life, and I never will.
For federal early retirees, the usual "last day of the month" rule doesn't apply because we're not eligible for a pension yet anyway. But federal leave payouts are based on your base rate in effect at the time you retire, so retiring January 1 is better than December 31 because it gives you the new (presumably ~1% higher) base pay rate, assuming Congress actually approves one.
Past January 1, it's a good idea to work long enough to show at least $5500 of earned income, so that you can max your Roth IRA for the year.
Past that, it makes sense to max out your 401k match. Federal TSP matches are up to 5% per paycheck, not based on your annual salary, so it doesn't help you as much to frontload them as much as it does at some private 401k plans, where you could presumably work just long enough to make the full 18k annual contribution. The problem here is that depending on your income level and family size, you may not have any taxable income anyway, if you only work for a few months of the year to max your 401k and Roth. In which case the 401k/TSP is only nominally better than your taxable investment account.
Beyond that, consider your SS contributions. Your SS payment is based on your 30 highest earning years, so you derive some benefit from working long enough to displace one of your lowest earning years. For most of us that's easy, since we're going to have a bunch of zeroes in our 30 year work history, having worked for less than 30 years.
Generally speaking, retiring at the end of a pay period will earn you whatever sick and annual leave were awarded for that pay period. It's only hours, but together might get you an extra day of pay. Similarly, count your paid holidays. If you get a free day off next week anyway, you might as well work four days and get paid for five more.
Figure out how your pension is calculated. Mine is based on months of service (with surplus days totalling less than one month discarded), so there's a tiny benefit to working an integer number of months in my entire career.
If you have kids (I do), and are planning on using the FAFSA simplifed needs test, things get significantly more complicated depending on the timing of their base year. Sometimes, it makes sense to deliberately limit your income in the year you retire, to qualify for additional aid.
If you have rental properties you're planning to sell (I do), then the timing of the sale matters for purposes of capital gains adding to your earned income. It would suck to go through all of the above math to maximize benefits, then crush it all because you suddenly get hit with $50k of capital gains from the sale of a property.
Do you want to apply for the EITC? If your dividend income is low enough, you can incur a negative tax rate by earning a few thousand dollars during the calendar year and qualifying for the EITC refund. It's potentially worth over $6k in free money.
How are your annual leave and sick leave credited? Do you get paid for them? Federal early retirees get royally shafted on this one, so it definitely makes sense to spend your leave balances down to zero by any means possible before you retire. Like if you've been postponing an elective surgery, the time to do it is before you retire so that you can bank a month or more of sick leave recovery time. Likewise for annual leave, take a series of long vacation is you have to, even if that means quitting on the day you get back from one. Don't pretend your employer cares about you by letting guilt convince you to not claim the benefits in your employment contract. They would fire you on the spot if they thought it financially prudent, so feel free to quit on the spot if you're really truly ready.
Do you get LWOP? Leave Without Pay is an option for some people, and in the case of federal employees LWOP of less than six months does not impact your summation of creditable service. Which means you can work six months and a day in a calendar year, take LWOP for the rest, and still have the entire year credited towards your pension calculation. It only gets you an extra half a percent of your high-3 (or high-5 if Republicans get their way), but it's not nothing.
For most of us, who are working professionals with good incomes, all of these details are effectively rounding errors. I'd be much better served to work a single extra month than to get all of the above exactly optimized. The extra income could go 100% to savings, generating returns indefinitely. And that's always been the problem with early retirees and the OMY problem. You start out crawling towards your goal, and then the journey accelerates continuously until you eventually rocket past your goal amount at warp speed. At that point, even slight delays on pulling the ER trigger are worth years and years of your earliest efforts.