changes['phases'] contains tuples for the phase transitions, which
provides a non-trivial overhead in Python. Replace this with a Python
dictionary containing 4 bit integers. Provide accessors to centralize
changes['phases'] procsessing in one place.
On average, this improves user time for issue5691 by 1% and peak RSS by
3MB.
Since this hook is the only user of tr.changes['phases']. I'd suggest disabling calculating tr.changes['phases'] if the hook does not exist.