The horizon codebase regularly creates jQuery objects based on the document (`$(document)`). This can happen many times in the same scope. For example, https://github.com/openstack/horizon/blob/1385db8d1f8358aca190a40ed4c341bfc3e46f56/horizon/static/horizon/js/horizon.instances.js shows it happening 8 different times.
This could be done once, saved to a variable, and then reused. Creating a jQuery object isn't cheap. By doing it many times as opposed to 1 we are causing more logic to fire, more memory to be allocated, and more work to happen in the browsers garbage collection.
By moving to a single variable and repeatedly using it we will use less memory, cause horizon to be faster, and other performance benefits.
Fix proposed to branch: master /review. openstack. org/148957
Review: https:/