How does a node compare two blockchains?
Block headers include a field called bits, which can be used to calculate the difficulty and hence the amount of proof-of-work in the chain. There's probably a shortcut to being able to eliminate a 100,000 longer chain, but all core does is calculate the proof-of-work present in both chains and take the one with more.

Note that block headers are only 80 bytes each, so the 500k blocks would only be about 40 MB, not an unreasonable amount of data to calculate how much proof-of-work a chain has.