A large number of mutable states can cause a error during code generation due to reaching the constant pool limit. There is an ongoing effort on
SPARK-18016 to fix the problem, nonetheless we can also alleviate it avoiding to create a global variables when they are not needed.
Therefore I am creating this umbrella ticket to track the elimination of usage of global variables where not needed. This is not a duplicate or an alternative to
SPARK-18016: this is a complementary effort which can help together with it to support wider datasets.