I don't know beans about Trainz' internal coding. That's a sad situation since I'm a little better at fussing with code than I am at building routes.
But we've all noticed that if you build a route creating tracks, then deleting mistakes and re-creating replacement tracks -- the numbers on the junctions and track markers which have been deleted are not reused. So the internal lists of junctions and markers must end up with many blank entries. Or maybe the internal list keeps the deleted numbers, but marks them as deleted.
Yesterday I built a small test route on a baseboard. Then deleted and replaced most of the low numbered track junctions. The route included a track marker at opposite ends. Then I created a session that instructed the train to go back and forth between the two markers. I ran the session once to make certain I didn't do anything dumb that kept it from working.
Then I used the compact route on it. The junctions and the track markers were indeed renumbered. I expected it to start renumbering at the first track that I laid and work to the last piece, but it didn't. I'm not remembering which track piece was the last to be laid, so I'm not certain why compact route started renumbering where it did. I suppose the track pieces themselves were also renumbered, but I've never tried to figure out the number of a piece of track. So I don't know what it did there.
With different numbered track markers, the session didn't work at all.
It also produced this error code:
DriverCharacter : File drivercharacter.gs, Line 497, ER_NullReference
function $void@DriverCharacter::ScheduleThread(), line 493
DriverSetupRule : DriverSetupRule> 1 errors during driver creation. Trains may be missing drivers and/or commands. (file interface.gs)
function $void@Interface::Exception(string), line -1
function $void@DriverSetupRule::CreateDrivers(), line 798
DriverCharacter : DriverCharacter.CreateSchedule> null driverTrain (file gs.gs)
function $void@GameObject::Exception(string), line -1
function $void@DriverCharacter::CreateSchedule(), line 320
function $void@DriverCharacter:

riverCustomCommand(CustomCommand), line 474
function $bool@DriveToTrackmarkScheduleCommand::UpdateExecute(DriverCharacter), line 136
function $bool@DriveToTrackmarkScheduleCommand::BeginExecute(DriverCharacter), line 114
I don't know if this is Lua or Java code. I haven't worked with either, but I've heard that earlier versions of Trainz used both.
So ... I still didn't answer any of the questions raised in this topic. Compact Route definitely seems to read through each of the splines in the route to remove all the deleted splines so that the internal tables or lists of splines are more compact. But I don't know what else it might be cleaning up.