Why do you want to optimise this? getheaders is used by SPV clients not full nodes. SPV clients like bitcoinj can and do simply ship with gist files in them, then getheaders from the last "checkpoint" (I wish I hadn't reused terminology like that but this is what bitcoinj calls them).
In practice when I look at performance issues with current SPV clients, getheaders speed is not on my radar.