The initial discussion regarding cues may be done reasonably early, as the edit is being put together; the director and composer will meet to discuss and hear basic ideas, sometimes even just on a piano played live over some key sections.
As the final edit is neared, and timings are closer to finalised, the cues can then be expanded into initial arrangements - these days quite likely on virtual instruments, rather than full recorded orchestrations.
As these days it's quite likely that the final edit will be known before the CGI is finished, there is then time to score and record the full orchestration without a great deal of rushing, re-timing, re-recording; as used to happen in the past.
As not all the score is necessarily orchestral, the virtual [synthesized] parts can be laid down separately; the composer having access to the movie on his computer at all times. Cues and tempi can be pre-mapped and even at the orchestral recording, the conductor can have click track and other audio cues on headphones, to keep the orchestra in tempo with the existing arrangement.
These days, for a big movie, it is unlikely that the "credited composer" will actually be just one person. He will very likely have a team of orchestrators working on his original ideas. Massive networked computer workstations can bring the virtualised orchestrations to near perfection before being physically scored on paper for the final recording.
Many movies will possibly never use an actual orchestra - though the massive budget blockbusters will, certainly for the main cues and themes.
It can be very difficult to spot when it's not real, these days.