Currently, partitions are generated first and then selected_allowed_partitions is used to discard elements that are not needed.
Maybe the allowed partitions could be already checked before generating them to increase efficiency.
This has a low priority.