Reduce the number of document jquery objects created

Bug #1412971 reported by mattfarina
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Low
Chris Johnson

Bug Description

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.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/148957

Changed in horizon:
assignee: nobody → mattfarina (mattfarina)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/148957
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=b48789e65704adf92737baccf245cc611b013e05
Submitter: Jenkins
Branch: master

commit b48789e65704adf92737baccf245cc611b013e05
Author: Matt Farina <email address hidden>
Date: Wed Jan 21 09:45:20 2015 -0500

    Remove extra jQuery object creation in horizon.instances.js

    Reduces the number of jQuery document objects from 8 to 1 using a variable.
    Removes the creation of redundant jQuery objects based on a selector.

    Change-Id: I9ed0815f4fd171cec49c66b73cc04addd46c820d
    Partial-Bug: #1412971

David Lyle (david-lyle)
Changed in horizon:
importance: Undecided → Low
milestone: none → kilo-2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/151275

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/151275
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=52f401457f4cbf37e52c92c7c27ac42710b54098
Submitter: Jenkins
Branch: master

commit 52f401457f4cbf37e52c92c7c27ac42710b54098
Author: Matt Farina <email address hidden>
Date: Thu Jan 29 10:15:28 2015 -0500

    Updates contribution guidelines for JS object performance

    In a new section, titled performance, a requirement is added
    for JavaScript code to limit the re-creation of objects in
    the same scope. An example with jQuery is given with explanation.

    Change-Id: I2f0d8392277f65384389d8d20154d645197050af
    Partial-Bug: #1412971

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/152908

Thierry Carrez (ttx)
Changed in horizon:
milestone: kilo-2 → kilo-3
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/152908
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=fe2dc1d8acc11e3e9a16264aed6bb62c21769582
Submitter: Jenkins
Branch: master

commit fe2dc1d8acc11e3e9a16264aed6bb62c21769582
Author: Matt Farina <email address hidden>
Date: Wed Feb 4 06:24:50 2015 -0800

    Remove extra jQuery object creation in horizon.modals.js

    Reduces the number of jQuery document objects from 7 to 1 using a variable.

    Change-Id: I7b1bf71512c1913854f94767b475fc04ecad2afc
    Partial-Bug: #1412971

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/162650

Changed in horizon:
assignee: mattfarina (mattfarina) → Chris Johnson (wchrisjohnson)
Changed in horizon:
assignee: Chris Johnson (wchrisjohnson) → nobody
assignee: nobody → Chris Johnson (wchrisjohnson)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/162650
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=2a8cad06742130eda7148ca6534c30cdf36c1dec
Submitter: Jenkins
Branch: master

commit 2a8cad06742130eda7148ca6534c30cdf36c1dec
Author: Chris Johnson <email address hidden>
Date: Mon Mar 9 10:59:34 2015 -0400

    Refactor multiple references to $(document)

    According to the Horizon Contributing Guide, we are to:
    "Avoid creating instances of the same object repeatedly
    within the same scope. Instead, assign the object to a
    variable and re-use the existing object."

    The guide references the use of "$(document)", as an
    example. And yet multiple examples can be found of that
    sort of approach. This commit cleans up those references.

    Partial-Bug: 1412971
    Change-Id: Ica05700101ae9a453623d928f07b75fa7aaca186

Thierry Carrez (ttx)
Changed in horizon:
milestone: kilo-3 → kilo-rc1
David Lyle (david-lyle)
Changed in horizon:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in horizon:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in horizon:
milestone: kilo-rc1 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.