{"id":1826,"date":"2009-09-19T23:30:04","date_gmt":"2009-09-20T06:30:04","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=1826"},"modified":"2009-09-22T14:46:48","modified_gmt":"2009-09-22T21:46:48","slug":"optimizing-away-arrows","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/","title":{"rendered":"Optimizing Away Arrows"},"content":{"rendered":"<p>Google released the third version of their year-old <a href=\"http:\/\/www.google.com\/chrome\">Chrome browser<\/a> this past week. This reminded me that they incorporate <a href=\"http:\/\/ffmpeg.org\/\">FFmpeg<\/a> into the software (and thanks to the devs for <a href=\"http:\/\/src.chromium.org\/viewvc\/chrome\/trunk\/deps\/third_party\/ffmpeg\/patches\/\">making various fixes available to us<\/a>). Chrome uses FFmpeg for decoding HTML5\/video tag-type video and accompanying audio. This always makes me wonder, <em>why would they use FFmpeg&#8217;s Theora decoder? It sucks. I should know; I wrote it.<\/em><\/p>\n<p>Last year, <a href=\"http:\/\/lists.mplayerhq.hu\/pipermail\/ffmpeg-devel\/2008-June\/047993.html\">Reimar discovered<\/a> that the VP3\/Theora decoder spent the vast majority of its time decoding the coefficient stream. He proposed a fix that made it faster. I got a chance to check out the decoder tonight and profile it with <a href=\"http:\/\/oprofile.sf.net\">OProfile<\/a> and FFmpeg&#8217;s own internal timer facilities. It turns out that the function named unpack_vlcs() is still responsible for 44-50% of the decoding time, depending on machine and sample file. This is mildly disconcerting considering the significant amount of effort I put forth to even make it that fast (it took a lot of VLC magic).<\/p>\n<p>So a function in a multimedia program is slow? Well, throw assembly language and SIMD instructions at the problem! Right? It&#8217;s not that simple with entropy decoders.<\/p>\n<p>Reimar had a good idea in his patch and I took it to its logical conclusion: Optimize away the arrows, i.e., structure dereferences. The function insists on repeatedly grabbing items out of arrays from a context structure. Thus, create local pointers to the same array and save a bunch of dereferences through each of the innumerable iterations.<\/p>\n<p>Results were positive&#8211; both OProfile and the TSC-based internal counter showed notable improvements.<\/p>\n<p>Ideas for further improvements: Multithreading is all the rage for video decoders these days. Unfortunately, entropy decoding is always a serial proposition. However, VP3\/Theora is in a unique position to take advantage of another multithreading opportunity: It could call reverse_dc_prediction() in a separate thread after all the DC coefficients are decoded. Finally, an upside to the algorithm&#8217;s unorthodox bitstream format! According to my OProfile reports, reverse_dc_prediction() consistently takes around 6-7% of the decode time. So it would probably be of benefit to remove that from the primary thread which would be busy with the AC coefficients.<\/p>\n<p>Taking advantage of multiple threads would likely help with the render_slice() function. One thing at a time, though. Wish me luck with presenting the de-dereferencing patch to the list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Banish dereferences from inner loops<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,33],"tags":[],"class_list":["post-1826","post","type-post","status-publish","format-standard","hentry","category-programming","category-vp3theora"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Banish dereferences from inner loops\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Multimedia Mike\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta property=\"og:description\" content=\"Banish dereferences from inner loops\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2009-09-20T06:30:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-09-22T21:46:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Banish dereferences from inner loops\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#article\",\"name\":\"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes\",\"headline\":\"Optimizing Away Arrows\",\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"},\"datePublished\":\"2009-09-19T23:30:04-07:00\",\"dateModified\":\"2009-09-22T14:46:48-07:00\",\"inLanguage\":\"en-US\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#webpage\"},\"articleSection\":\"Programming, VP3\\\/Theora\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"position\":2,\"name\":\"Programming\",\"item\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#listItem\",\"name\":\"Optimizing Away Arrows\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#listItem\",\"position\":3,\"name\":\"Optimizing Away Arrows\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/category\\\/programming\\\/#listItem\",\"name\":\"Programming\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/\",\"name\":\"Multimedia Mike\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Multimedia Mike\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#webpage\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/\",\"name\":\"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes\",\"description\":\"Banish dereferences from inner loops\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/optimizing-away-arrows\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/author\\\/multimedia-mike\\\/#author\"},\"datePublished\":\"2009-09-19T23:30:04-07:00\",\"dateModified\":\"2009-09-22T14:46:48-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#website\",\"url\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/\",\"name\":\"Breaking Eggs And Making Omelettes\",\"description\":\"Topics On Multimedia Technology and Reverse Engineering\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/multimedia.cx\\\/eggs\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes","description":"Banish dereferences from inner loops","canonical_url":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#article","name":"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes","headline":"Optimizing Away Arrows","author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"},"datePublished":"2009-09-19T23:30:04-07:00","dateModified":"2009-09-22T14:46:48-07:00","inLanguage":"en-US","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#webpage"},"isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#webpage"},"articleSection":"Programming, VP3\/Theora"},{"@type":"BreadcrumbList","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs#listItem","position":1,"name":"Home","item":"https:\/\/multimedia.cx\/eggs","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","name":"Programming"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","position":2,"name":"Programming","item":"https:\/\/multimedia.cx\/eggs\/category\/programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#listItem","name":"Optimizing Away Arrows"},"previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#listItem","position":3,"name":"Optimizing Away Arrows","previousItem":{"@type":"ListItem","@id":"https:\/\/multimedia.cx\/eggs\/category\/programming\/#listItem","name":"Programming"}}]},{"@type":"Organization","@id":"https:\/\/multimedia.cx\/eggs\/#organization","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","url":"https:\/\/multimedia.cx\/eggs\/"},{"@type":"Person","@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author","url":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/","name":"Multimedia Mike","image":{"@type":"ImageObject","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/2eb93f7cada658f7986b5092062849fa255779eada3342c8f6b9a40764b95fdd?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Multimedia Mike"}},{"@type":"WebPage","@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#webpage","url":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/","name":"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes","description":"Banish dereferences from inner loops","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/multimedia.cx\/eggs\/#website"},"breadcrumb":{"@id":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/#breadcrumblist"},"author":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"creator":{"@id":"https:\/\/multimedia.cx\/eggs\/author\/multimedia-mike\/#author"},"datePublished":"2009-09-19T23:30:04-07:00","dateModified":"2009-09-22T14:46:48-07:00"},{"@type":"WebSite","@id":"https:\/\/multimedia.cx\/eggs\/#website","url":"https:\/\/multimedia.cx\/eggs\/","name":"Breaking Eggs And Making Omelettes","description":"Topics On Multimedia Technology and Reverse Engineering","inLanguage":"en-US","publisher":{"@id":"https:\/\/multimedia.cx\/eggs\/#organization"}}]},"og:locale":"en_US","og:site_name":"Breaking Eggs And Making Omelettes | Topics On Multimedia Technology and Reverse Engineering","og:type":"article","og:title":"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes","og:description":"Banish dereferences from inner loops","og:url":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/","article:published_time":"2009-09-20T06:30:04+00:00","article:modified_time":"2009-09-22T21:46:48+00:00","twitter:card":"summary","twitter:title":"Optimizing Code By Eliminating Dereferences | Breaking Eggs And Making Omelettes","twitter:description":"Banish dereferences from inner loops"},"aioseo_meta_data":{"post_id":"1826","title":"Optimizing Code By Eliminating Dereferences | #site_title","description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2020-12-31 22:01:17","updated":"2025-12-31 19:16:01","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/multimedia.cx\/eggs\/category\/programming\/\" title=\"Programming\">Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tOptimizing Away Arrows\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/multimedia.cx\/eggs"},{"label":"Programming","link":"https:\/\/multimedia.cx\/eggs\/category\/programming\/"},{"label":"Optimizing Away Arrows","link":"https:\/\/multimedia.cx\/eggs\/optimizing-away-arrows\/"}],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=1826"}],"version-history":[{"count":8,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1826\/revisions"}],"predecessor-version":[{"id":1834,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/1826\/revisions\/1834"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=1826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=1826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=1826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}