replace table.sort with a custom introsort implementation (about 3x faster than vanilla table.sort)