{"action":"created","issue":{"url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/9","labels_url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/9/comments","events_url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/9/events","html_url":"https://github.com/jennschiffer/timbles.js/pull/9","id":111717965,"number":9,"title":"Simplifying and speeding up init and sortMap creation","user":{"login":"edelooff","id":490090,"avatar_url":"https://avatars.githubusercontent.com/u/490090?v=3","gravatar_id":"","url":"https://api.github.com/users/edelooff","html_url":"https://github.com/edelooff","followers_url":"https://api.github.com/users/edelooff/followers","following_url":"https://api.github.com/users/edelooff/following{/other_user}","gists_url":"https://api.github.com/users/edelooff/gists{/gist_id}","starred_url":"https://api.github.com/users/edelooff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edelooff/subscriptions","organizations_url":"https://api.github.com/users/edelooff/orgs","repos_url":"https://api.github.com/users/edelooff/repos","events_url":"https://api.github.com/users/edelooff/events{/privacy}","received_events_url":"https://api.github.com/users/edelooff/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-15T22:06:27Z","updated_at":"2015-10-27T14:33:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jennschiffer/timbles.js/pulls/9","html_url":"https://github.com/jennschiffer/timbles.js/pull/9","diff_url":"https://github.com/jennschiffer/timbles.js/pull/9.diff","patch_url":"https://github.com/jennschiffer/timbles.js/pull/9.patch"},"body":"This PR speeds up Timbles initialization and the creation of the sortMap used to actually sort the table based on the selected column.\r\n\r\nInitialization no longer uses the IDs of the column headers at all (though these can still be used as sorting targets like before), and simply stores a column index as (jQuery) data attribute on each header. A significant speedup is accomplished by adding a class to each and every `tbody td`. This significantly reduces setup time for large tables.\r\n\r\nThis change of initialization also removes the need for the `timblesAnonCount` global variable used to assign unique IDs to column heads.\r\n\r\nSecond is a change to the event handler for the click, this is now handled by `sortColumnEvent`, and `sortColumn` is maintained as public API for script access. The revised `sortColumn()` function can either sort by ID string of the column as before, or numeric 0-based index.\r\n\r\nWith the change from class-based to position-based extraction of the correct column comes the opportunity to do this in native JS/DOM, which makes sortMap about an order of magnitude faster. This is due to accessing child elements of the `<tr>` directly and retrieving the nth element needed, as well as using native getters for the data attribute (with jQuery style automatic conversion of numbers) and text nodes (including IE's non-standard attribute).\r\n\r\nThe sortMap has also been changed to store a reference to the entire row rather than its index, making the shuffling of rows post-sort a more understandable `.each()` call.\r\n\r\nThe time taken by `sortColumnEvent()` for my 2300 row test table is now down to ~110ms (from ~200ms before), and is dominated by the detaching of the `<tbody>`:\r\n\r\n* Creating the sortMap takes ~**5ms**\r\n* Actually sorting it takes ~**5ms**\r\n* Detaching the tbody ~**80ms**\r\n* Shuffling rows based on the sortMap* ~**20ms**  \r\n  \\* Reattaching is also done in this time\r\n\r\nNot detaching slows the shuffling down by over an order of magnitude (20ms to 250ms). There appears to be no speeding up the detaching significantly (setting `innerHTML`, using `Node.removeChild()` or `Node.replaceChild()`), so this seems to be as fast as it reasonably gets.\r\n\r\nThere's probably some documentation / tests that should be updated/added as well, but I wanted to get this rolling as it's been sitting for too long."},"comment":{"url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/comments/151519150","html_url":"https://github.com/jennschiffer/timbles.js/pull/9#issuecomment-151519150","issue_url":"https://api.github.com/repos/jennschiffer/timbles.js/issues/9","id":151519150,"user":{"login":"jennschiffer","id":341305,"avatar_url":"https://avatars.githubusercontent.com/u/341305?v=3","gravatar_id":"","url":"https://api.github.com/users/jennschiffer","html_url":"https://github.com/jennschiffer","followers_url":"https://api.github.com/users/jennschiffer/followers","following_url":"https://api.github.com/users/jennschiffer/following{/other_user}","gists_url":"https://api.github.com/users/jennschiffer/gists{/gist_id}","starred_url":"https://api.github.com/users/jennschiffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennschiffer/subscriptions","organizations_url":"https://api.github.com/users/jennschiffer/orgs","repos_url":"https://api.github.com/users/jennschiffer/repos","events_url":"https://api.github.com/users/jennschiffer/events{/privacy}","received_events_url":"https://api.github.com/users/jennschiffer/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T14:33:45Z","updated_at":"2015-10-27T14:33:45Z","body":"hey - sorry I got to this so late.\r\nI checked out the PR locally and a bunch of the tests are failing from script errors - can you take a look? I think all the weirdness is happening in the sorting part."}}