Kevin Bacon Code Contest Performance Optimization 11/16/2015

Embed Size (px)

Citation preview

Kevin Bacon Code Contest Performance Optimization 11/16/2015 How the app works Gets the Seed Page Look up the link using HTTP Loads HTML into HTML Agility Pack Get all the href (links) For each link Check if weve already looked up that link (AllUrlsTraversed [ArrayList]) Check if its the final link If not, then look up that link Youre Done! Big issues Single-Threaded HTTP is asynchronous and takes time Need to change to multi-threading Perf Profiler Performance Profiling in Visual Studio https://msdn.microsoft.com/en-us/library/ms aspx https://msdn.microsoft.com/en-us/library/ms aspx Perf Profiler Choose the right collection CollectionOrderingContiguous Storage? Direct Access?Lookup EfficiencyManipulate Efficiency Notes DictionaryUnorderedYesVia KeyKey: O(1) Best for high performance lookups. SortedDictionarySortedNoVia KeyKey: O(log n) O(log n) Compromise of Dictionary speed and ordering, uses binarysearch tree. SortedListSortedYesVia KeyKey: O(log n) O(n)Very similar toSortedDictionary, except tree is implemented in an array, so has faster lookup on preloaded data, but slower loads. List User has precise control over element ordering YesVia IndexIndex: O(1) Value: O(n) O(n)Best for smaller lists where direct access required and no sorting. LinkedList User has precise control over element ordering No Value: O(n) O(1)Best for lists where inserting/deleting in middle is common and no direct access required. HashSetUnorderedYes Via Key Key: O(1) Unique unordered collection, like a Dictionary except key and value are same object. SortedSetSortedNoVia KeyKey: O(log n) Unique sorted collection, like SortedDictionary except key and value are same object. StackLIFOYesOnly TopTop: O(1)O(1)*Essentially same as List except only process as LIFO QueueFIFOYesOnly FrontFront: O(1)O(1)Essentially same as List except only process as FIFO 13 minutes 26 seconds What Next? Whats next Loading the doc into the HTML Agility Pack is taking 60% of processing time. Perhaps I could just read the string directly and do a simpler parse function