BUG #13726. Fixing performance issues with updating variables.

This fixes the performance issue still observed after the supposed fix
d8446c652c. The issue was that we were still ending up with a list that updated
the item multiple times. Updating the internal datastructures to create the
smallest possible list of items that need updating. This addresses the issue.

Change-Id: I878c5171b9a174d51b0ac853adba6b05f77be66a
Merge topic '13726_fix_variable_selection_performance' into next

d428305 BUG #13726. Fixing performance issues with updating variables.