It would make sense to announce a vice presidential candidate one or two weeks before the convention, so that the running mate has enough time to adjust to being on the national stage, but has not been a known entity for so long that they seem stale when they are introduced to the Americans who only begin tracking the overall election when the conventions begin.
There doesn't seem to be much of a use waiting until the second day of the convention to announce a running mate, since there is usually only a
small bounce for a party after naming vice-presidential candidates.
If there were a unique situation in which a party seemed fractured between two leading candidates, it would probably be best for the presidential nominee to announce their running mate immediately after he or she sewed up the nomination as a means of unity. To make this scenario clearer, imagine an even harsher primary battle between Barack Obama and Hillary Clinton than what actually occurred in 2008. Naturally, Obama would have wanted to quickly unite the party and focus on the general election, so he probably would have made his vice-presidential announcement at the beginning of June when he defeated Hillary, instead of the real-life date of August 23.