sort() only once in state.Compiler.order_chunks()

refactor a bit further per @gldnspud in #4836
Merge pull request #4855 from hulu/sort-once

sort() only once in state.Compiler.order_chunks()