yui/yui3 — pull request #1606 by ezequiel (2014-02-03 10:28:25+00:00)
Title: [Loader] : `calculate` optimization.

This is a first attempt at optimizing `Y.Loader`, since it actually bubbled up as a bottleneck in a certain application. I simply rewrote `_sort`, which now utilizes a topological sort (a variation of a depth first search) to generate a valid dependency order.

# Before
The following is a profile of `Y.Loader`'s `resolve` method. `_sort` bubbled up as one of the slowest methods `calculate` calls (which, in turn, `resolve` calls), so I decided to start there.

**Note**: *Inclusive time* is the time spent in the function, *and* its children. *Exclusive time* is the time spent in *just* the function, excluding its children.
![loader_profile_before](https://f.cloud.github.com/assets/368069/2063562/24ff90f2-8cb9-11e3-8c5f-3a2ba4c00126.jpg)

### Operations/second of `calculate`:
┌──────────────────────────────────────────┐
│ Internet Explorer (11.0) / Windows 8.1 │
├──────────────────────────────────────────┤
│ 94.766 ±3.3% │
└──────────────────────────────────────────┘

# After
![loader_profile_after](https://f.cloud.github.com/assets/368069/2063564/26fa78a4-8cb9-11e3-9b1b-a1ff4d9a891e.jpg)

### Operations/second of `calculate`:
┌──────────────────────────────────────────┐
│ Internet Explorer (11.0) / Windows 8.1 │
├──────────────────────────────────────────┤
│ 263.343 ±3.2% │
└──────────────────────────────────────────┘

--------

**Notes**:

* After the rewrite, the op/s rose from 94.766 to 263.343. That's a **177.9%** difference!

* Five unit tests were tweaked because they relied on `resolve(..).js` or `resolve(..).css` returning a certain order. There are times in which the order does not matter. For example, order does not matter if both modules do not depend on one another. I've made comments on each of these tests.

* I'm still nervous as to whether there are **any** edge cases I haven't caught. All 11000+ unit tests are successful, and amongst them are ones with pretty good coverage (`app`).

@ekashida @caridy