#483 ✓ staged
Scott Downe

performance issues with addtrackevent

Reported by Scott Downe | April 18th, 2011 @ 05:44 PM | in 0.6

Up to this point, this hasn't been that huge of a deal because the number of tracks being added has been relatively small, roughly 100 tracks most?

I just helped on a demo where roughly 5938 (exactly) tracks were being created.

I hacked up popcorn to make this work by moving the sorting outside of addtrackevent.

I think we can do better, I want to optimize this area.

Comments and changes to this ticket

  • Rick

    Rick May 8th, 2011 @ 08:41 PM

    • State changed from “new” to “assigned”
    • Assigned user set to “Scott Downe”

    Tough one...

    Looking at the code now and wondering how you'll manage switching between not sorting and sorting

  • Scott Downe

    Scott Downe May 8th, 2011 @ 09:57 PM

    I have a few ideas I want to try, but I will need a day of focus to write, test and compare each solution in various contexts.

    The idea is to try and sort less often or once only after all or most of the tracks are added. We can sorted a sorted or not state, set it to false when a track is added, and sort once inside timeupdate and setting sorted to true. This has the disadvantage of unloading some of the work onto an already time sensitive part of the code.

    Another option is to not push into the array, but drop the track into the right spot manually. I will need to test various ways of doing this. Splice comes to mind, but I fear it is going to be marginally better than sort.

    Another is to sort by default after each addtrack, with the option to not sort, and create an explicit sort that the user calls on their own if they are working with a large number of tracks.

    I'll tackle this Wednesday, so if anyone's got any ideas before then, let's brainstorm a bit.

  • Rick

    Rick May 8th, 2011 @ 10:06 PM

    I'm tuned nto this pretty tightly now, so I'll likely ping you tomorrow with some ideas.

  • Scott Downe

    Scott Downe May 11th, 2011 @ 01:46 PM

    • State changed from “assigned” to “peer-review-requested”
    • Milestone order changed from “35” to “0”


    Here is a perf test for the old code and the new code: http://jsperf.com/popcornjs-addtrackevent/5

    Huge thanks to Rick on this one.

  • Scott Downe

    Scott Downe May 11th, 2011 @ 01:47 PM

    • Assigned user cleared.
  • Rick

    Rick May 11th, 2011 @ 02:27 PM

    Don't thank me, it was team work that pulled this off. 23,891% performance improvement :D

  • Rick

    Rick May 13th, 2011 @ 04:51 PM

    • State changed from “peer-review-requested” to “super-review-requested”
    • Assigned user set to “annasob”

    This was co-written by both of us, so I PR+

  • annasob

    annasob May 15th, 2011 @ 11:43 AM

    • State changed from “super-review-requested” to “review-looks-good”

    This looks good but has no test :( I guess the real test will come when Scott does the word-river plugin. I ran the semantic_video demo and the plugins and the seem to work fine. There is one lint error that can be ninja commited:

    for ( var idx = byEnd.length-1; idx >= 0; idx-- ) {
        Problem at line 591 character 19: 'idx' is already defined.


  • Rick

    Rick May 15th, 2011 @ 12:33 PM

    Anything that is performance or memory management related is basically impossible to unit test, however this is where the unit tests really shine as they guided Scott and I through the process, from concept to stable commit.

    Meanwhile, the results at http://jsperf.com/popcornjs-addtrackevent/5 are the best way to gauge the impact of our changes (the numbers under the "alt" column are the new speed results, higher is better)

  • annasob

    annasob May 15th, 2011 @ 01:17 PM

    • State changed from “review-looks-good” to “staged”

    Staged in annasob/popcorn-js commit

  • Rick

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Popcorn.js is an HTML5 video framework that lets you bring elements of the web into your videos.

Popcorn.js is a project of Web Made Movies, Mozilla's Open Video Lab.

Shared Ticket Bins

Referenced by