Better performance of `bagof/3` and `setof/3` calls with goals only known at runtime