{"action":"created","issue":{"url":"https://api.github.com/repos/kohler/gifsicle/issues/47","labels_url":"https://api.github.com/repos/kohler/gifsicle/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/kohler/gifsicle/issues/47/comments","events_url":"https://api.github.com/repos/kohler/gifsicle/issues/47/events","html_url":"https://github.com/kohler/gifsicle/pull/47","id":96900422,"number":47,"title":"Threaded Resize for Gifsicle","user":{"login":"wilkesybear","id":6982027,"avatar_url":"https://avatars.githubusercontent.com/u/6982027?v=3","gravatar_id":"","url":"https://api.github.com/users/wilkesybear","html_url":"https://github.com/wilkesybear","followers_url":"https://api.github.com/users/wilkesybear/followers","following_url":"https://api.github.com/users/wilkesybear/following{/other_user}","gists_url":"https://api.github.com/users/wilkesybear/gists{/gist_id}","starred_url":"https://api.github.com/users/wilkesybear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilkesybear/subscriptions","organizations_url":"https://api.github.com/users/wilkesybear/orgs","repos_url":"https://api.github.com/users/wilkesybear/repos","events_url":"https://api.github.com/users/wilkesybear/events{/privacy}","received_events_url":"https://api.github.com/users/wilkesybear/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-07-23T20:37:30Z","updated_at":"2015-08-04T18:34:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/kohler/gifsicle/pulls/47","html_url":"https://github.com/kohler/gifsicle/pull/47","diff_url":"https://github.com/kohler/gifsicle/pull/47.diff","patch_url":"https://github.com/kohler/gifsicle/pull/47.patch"},"body":"**What**\r\nThese changes will build gifsicle with the pthread library and allow a parallel resize with the \r\n`--threaded-resize=<threads>` or `-T<threads>`\r\noption. The user can specify the max number of threads to have open at a time, or just use the default (currently 32, but that's probably too high for most machines). \r\n\r\nIn order to resize images in parallel, unoptimizing (and re-optimizing on write) is required to make each frame independently resize-able. Despite this overhead, I have found threaded resize to be faster than the original by 1.5-2x in my testing. While the output isn't the same pixel-for-pixel (because of reoptimization), sizes tend to be slightly smaller as long as the source gif didn't come from gifsicle itself.\r\n\r\n**Why**\r\nThis is part of an effort by Tumblr (where I work) to speed up the time to resize a gif, at the expense of burning a hole in our CPUs. I hope to use this version of **t**hreaded **gifsicle** (I call it TGIFsicle!) to deliver resized gifs faster to our users.\r\n\r\n**Performance**\r\nTesting on a macbook pro: 8gb RAM (DDR3 1600 MHz), Intel Core i7-4558U CPU @ 2.80GHz\r\nTaking a 500-gif subset from https://gist.github.com/wilkesybear/22fb18106dab7579a7fe (warning, not all of these gifs are SFW), I resized each gif into a handful of smaller sizes. Here are some results. Each run had a total 1,525 resizes done\r\n\r\nThreads  | Total Time (s) | Average Time (s)\r\n------------- | ------------- | -------------\r\n1 (gifsicle)  | 482 | .317\r\n4 | 366 | .240\r\n8  | 287 | .188\r\n16  | 291 | .191\r\n32 | 320 | .210\r\n\r\nSpecifically, each of the URLs in the gist above has a size (e.g. `..._500.gif`) that indicates the bounding box for the image. Tumblr has a predefined set of supported bounding box sizes, so the test only resizes the image to smaller bounding boxes (e.g. a `_500.gif` input will be resized to `_400`, `_250`, etc. but not for `_640`, a no-op). Timing does not include the curl, only the time spent in the call to `gifsicle`\r\n\r\n*Caveat:* I haven't tried to build this on windows, but I have no reason to believe that it will work. This compiles and runs on Mac and Linux distributions"},"comment":{"url":"https://api.github.com/repos/kohler/gifsicle/issues/comments/127705516","html_url":"https://github.com/kohler/gifsicle/pull/47#issuecomment-127705516","issue_url":"https://api.github.com/repos/kohler/gifsicle/issues/47","id":127705516,"user":{"login":"wilkesybear","id":6982027,"avatar_url":"https://avatars.githubusercontent.com/u/6982027?v=3","gravatar_id":"","url":"https://api.github.com/users/wilkesybear","html_url":"https://github.com/wilkesybear","followers_url":"https://api.github.com/users/wilkesybear/followers","following_url":"https://api.github.com/users/wilkesybear/following{/other_user}","gists_url":"https://api.github.com/users/wilkesybear/gists{/gist_id}","starred_url":"https://api.github.com/users/wilkesybear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilkesybear/subscriptions","organizations_url":"https://api.github.com/users/wilkesybear/orgs","repos_url":"https://api.github.com/users/wilkesybear/repos","events_url":"https://api.github.com/users/wilkesybear/events{/privacy}","received_events_url":"https://api.github.com/users/wilkesybear/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T18:34:35Z","updated_at":"2015-08-04T18:34:35Z","body":"Redid the benchmarking as described above, this time with 1000 gifs instead of 500 and with `--enable-simd`. Each of these sets involved doing total 2,980 resizes:\r\n\r\nThreads  | Total Time (s) | Average Time (s)\r\n------------- | ------------- | -------------\r\n1 (gifsicle)  | 785 | .264\r\n8  | 481 | .161\r\n16  | 479 | .161\r\n\r\nThe simd shows good improvements on my branch as well. \r\n"}}