Optimize DOM elements sorting