Imporve performance for BuildVariantMatrix