joshtynjala/feathers — pull request #650 by Fraggle (2013-08-21 08:31:41+00:00)
Title: Optmization of addControl / queue sorting

Hi Josh,

I did some inspection with Scout and I was able to improve significantly the performance of feather when adding controls, especially on mobile (one of my screen "feathers" init time was reduced from 1.5s to 200ms).

There are 2 changes:

• I moved the check if the control is already queued before the loop and using an indexOf, I dont believe it change anything to the logic and it's already quite an improvement.

• After careful thoughts, I removed the loop at each "addControl" call and just append to the end of the queue, then, I sort the queue just before validating the elements in it. The sort is based on the "depth" of the elements wich Is not exactly the same as what you did before with the looping and the splicing but I believe it keep the rule of validating the parent of a en element in priority.
The idea was to remove the call to contains() on every queued element each time an element is added. It is quite costy and since there is no cache of the "parents chain", the number of traversals increase quickly if you add a lot of elements.

I'm not particulary fan of the way I coded the calculateDepth and compareDepth function but it seems to work fine without any side-effect.

I would be very happy if you could merge those changes :)
---
Rewrite a bit of code to avoid looping thru all controls already in the
queue each time an element is added.
Then sort the queue just before validating the controls in it based on
the depth of the elements.