The contexts you see in the new data structure are just those that were used for printing characters, right? This means that just merging equal contexts is not sufficient (to generate good code). I.e., go-to-size-9 red text end-red blue text end-blue end-size-9 Clearly you want to merge the size 9 part of the contexts. The important decision is when the first use of a context is and when the last use is.