make dim_max_distinct_rules faster