Index building with less memory footprint