{"action":"closed","number":809,"pull_request":{"url":"https://api.github.com/repos/jcupitt/libvips/pulls/809","id":153509204,"node_id":"MDExOlB1bGxSZXF1ZXN0MTUzNTA5MjA0","html_url":"https://github.com/jcupitt/libvips/pull/809","diff_url":"https://github.com/jcupitt/libvips/pull/809.diff","patch_url":"https://github.com/jcupitt/libvips/pull/809.patch","issue_url":"https://api.github.com/repos/jcupitt/libvips/issues/809","number":809,"state":"closed","locked":false,"title":"Smartcrop: ~15% speedup via a linecache","user":{"login":"lovell","id":210965,"node_id":"MDQ6VXNlcjIxMDk2NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/210965?v=4","gravatar_id":"","url":"https://api.github.com/users/lovell","html_url":"https://github.com/lovell","followers_url":"https://api.github.com/users/lovell/followers","following_url":"https://api.github.com/users/lovell/following{/other_user}","gists_url":"https://api.github.com/users/lovell/gists{/gist_id}","starred_url":"https://api.github.com/users/lovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lovell/subscriptions","organizations_url":"https://api.github.com/users/lovell/orgs","repos_url":"https://api.github.com/users/lovell/repos","events_url":"https://api.github.com/users/lovell/events{/privacy}","received_events_url":"https://api.github.com/users/lovell/received_events","type":"User","site_admin":false},"body":"Hi John, I've been doing a little profiling of the \"attention\" smartcrop, in this case attempting to extract a 100x10000 region from a 10000x10000 input image.\r\n\r\nCurrent behaviour (gcc 5.4 `-O3`):\r\n```\r\n$ time vips smartcrop 10000x10000.v out.v 100 10000\r\nreal    0m18.825s\r\nuser    0m18.572s\r\nsys     0m0.284s\r\n```\r\n\r\n```\r\n36,788,404,121  ???:vips_extract_band_buffer [/usr/local/lib/libvips.so.42.8.0]\r\n15,708,124,763  /build/glibc-bfm8X4/glibc-2.23/math/../sysdeps/ieee754/dbl-64/e_atan2.c:__ieee754_atan2_avx [/lib/x86_64-linux-gnu/libm-2.23.so]\r\n14,953,036,753  ???:vips_col_sRGB2scRGB_8 [/usr/local/lib/libvips.so.42.8.0]\r\n12,562,353,888  ???:vips_ifthenelse_gen [/usr/local/lib/libvips.so.42.8.0]\r\n12,262,089,216  ???:vips_bandjoin_buffer [/usr/local/lib/libvips.so.42.8.0]\r\n10,367,136,011  ???:vips_XYZ2Lab_line [/usr/local/lib/libvips.so.42.8.0]\r\n 6,880,982,698  ???:vips_sRGB2scRGB_gen [/usr/local/lib/libvips.so.42.8.0]\r\n 6,878,396,905  ???:vips_col_scRGB2XYZ [/usr/local/lib/libvips.so.42.8.0]\r\n 5,883,590,511  ???:vips_convi_gen'2 [/usr/local/lib/libvips.so.42.8.0]\r\n```\r\n\r\nI noticed there's a 3-way split in the middle of the `vips_smartcrop_attention` pipeline. Adding a linecache operation just before, as this PR demonstrates, yields a ~15% performance improvement:\r\n\r\n```\r\n$ time vips smartcrop 10000x10000.v out.v 100 10000\r\nreal    0m15.592s\r\nuser    0m15.544s\r\nsys     0m0.084s\r\n```\r\n\r\n```\r\n28,810,327,781  ???:vips_extract_band_buffer [/usr/local/lib/libvips.so.42.8.0]\r\n15,708,124,763  /build/glibc-bfm8X4/glibc-2.23/math/../sysdeps/ieee754/dbl-64/e_atan2.c:__ieee754_atan2_avx [/lib/x86_64-linux-gnu/libm-2.23.so]\r\n12,562,353,888  ???:vips_ifthenelse_gen [/usr/local/lib/libvips.so.42.8.0]\r\n12,262,089,216  ???:vips_bandjoin_buffer [/usr/local/lib/libvips.so.42.8.0]\r\n10,367,136,011  ???:vips_XYZ2Lab_line [/usr/local/lib/libvips.so.42.8.0]\r\n 5,883,590,511  ???:vips_convi_gen'2 [/usr/local/lib/libvips.so.42.8.0]\r\n```\r\n\r\nThis removes a lot of over-computation, especially reducing calls to the seemingly expensive `vips_extract_band_buffer` and sRGB to scRGB pixel conversion.\r\n\r\nThe added `vips_linecache` operation is using mostly default parameters so I'm sure it can be improved further. There's probably a better place for it too, or perhaps more than one cache would help?\r\n\r\nI had a quick look at the auto-vectorisation of `vips_extract_band_buffer` but there's not a lot that can be done to improve things here given the input pixel stride is typically 12 bytes (3-band double) and therefore not a power of 2.\r\n\r\nThe presence of `atan2` in the callgrind report suggests the XYZ to LCH conversion is quite costly also. I've yet not had a chance to look at what might be possible to improve this.","created_at":"2017-11-19T18:39:26Z","updated_at":"2018-09-05T22:06:54Z","closed_at":"2018-09-05T22:06:54Z","merged_at":null,"merge_commit_sha":"8fbb01424317ceb803c4dd0cd2caefb5936bd360","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/jcupitt/libvips/pulls/809/commits","review_comments_url":"https://api.github.com/repos/jcupitt/libvips/pulls/809/comments","review_comment_url":"https://api.github.com/repos/jcupitt/libvips/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jcupitt/libvips/issues/809/comments","statuses_url":"https://api.github.com/repos/jcupitt/libvips/statuses/7ac034202087c840158b06f609d3c1ad85092bfb","head":{"label":"lovell:attention-smartcrop-linecache","ref":"attention-smartcrop-linecache","sha":"7ac034202087c840158b06f609d3c1ad85092bfb","user":{"login":"lovell","id":210965,"node_id":"MDQ6VXNlcjIxMDk2NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/210965?v=4","gravatar_id":"","url":"https://api.github.com/users/lovell","html_url":"https://github.com/lovell","followers_url":"https://api.github.com/users/lovell/followers","following_url":"https://api.github.com/users/lovell/following{/other_user}","gists_url":"https://api.github.com/users/lovell/gists{/gist_id}","starred_url":"https://api.github.com/users/lovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lovell/subscriptions","organizations_url":"https://api.github.com/users/lovell/orgs","repos_url":"https://api.github.com/users/lovell/repos","events_url":"https://api.github.com/users/lovell/events{/privacy}","received_events_url":"https://api.github.com/users/lovell/received_events","type":"User","site_admin":false},"repo":{"id":12671574,"node_id":"MDEwOlJlcG9zaXRvcnkxMjY3MTU3NA==","name":"libvips","full_name":"lovell/libvips","owner":{"login":"lovell","id":210965,"node_id":"MDQ6VXNlcjIxMDk2NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/210965?v=4","gravatar_id":"","url":"https://api.github.com/users/lovell","html_url":"https://github.com/lovell","followers_url":"https://api.github.com/users/lovell/followers","following_url":"https://api.github.com/users/lovell/following{/other_user}","gists_url":"https://api.github.com/users/lovell/gists{/gist_id}","starred_url":"https://api.github.com/users/lovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lovell/subscriptions","organizations_url":"https://api.github.com/users/lovell/orgs","repos_url":"https://api.github.com/users/lovell/repos","events_url":"https://api.github.com/users/lovell/events{/privacy}","received_events_url":"https://api.github.com/users/lovell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lovell/libvips","description":"A fast image processing library with low memory needs.","fork":true,"url":"https://api.github.com/repos/lovell/libvips","forks_url":"https://api.github.com/repos/lovell/libvips/forks","keys_url":"https://api.github.com/repos/lovell/libvips/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lovell/libvips/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lovell/libvips/teams","hooks_url":"https://api.github.com/repos/lovell/libvips/hooks","issue_events_url":"https://api.github.com/repos/lovell/libvips/issues/events{/number}","events_url":"https://api.github.com/repos/lovell/libvips/events","assignees_url":"https://api.github.com/repos/lovell/libvips/assignees{/user}","branches_url":"https://api.github.com/repos/lovell/libvips/branches{/branch}","tags_url":"https://api.github.com/repos/lovell/libvips/tags","blobs_url":"https://api.github.com/repos/lovell/libvips/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lovell/libvips/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lovell/libvips/git/refs{/sha}","trees_url":"https://api.github.com/repos/lovell/libvips/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lovell/libvips/statuses/{sha}","languages_url":"https://api.github.com/repos/lovell/libvips/languages","stargazers_url":"https://api.github.com/repos/lovell/libvips/stargazers","contributors_url":"https://api.github.com/repos/lovell/libvips/contributors","subscribers_url":"https://api.github.com/repos/lovell/libvips/subscribers","subscription_url":"https://api.github.com/repos/lovell/libvips/subscription","commits_url":"https://api.github.com/repos/lovell/libvips/commits{/sha}","git_commits_url":"https://api.github.com/repos/lovell/libvips/git/commits{/sha}","comments_url":"https://api.github.com/repos/lovell/libvips/comments{/number}","issue_comment_url":"https://api.github.com/repos/lovell/libvips/issues/comments{/number}","contents_url":"https://api.github.com/repos/lovell/libvips/contents/{+path}","compare_url":"https://api.github.com/repos/lovell/libvips/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lovell/libvips/merges","archive_url":"https://api.github.com/repos/lovell/libvips/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lovell/libvips/downloads","issues_url":"https://api.github.com/repos/lovell/libvips/issues{/number}","pulls_url":"https://api.github.com/repos/lovell/libvips/pulls{/number}","milestones_url":"https://api.github.com/repos/lovell/libvips/milestones{/number}","notifications_url":"https://api.github.com/repos/lovell/libvips/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lovell/libvips/labels{/name}","releases_url":"https://api.github.com/repos/lovell/libvips/releases{/id}","deployments_url":"https://api.github.com/repos/lovell/libvips/deployments","created_at":"2013-09-07T21:09:00Z","updated_at":"2018-09-05T20:03:07Z","pushed_at":"2018-09-05T20:03:12Z","git_url":"git://github.com/lovell/libvips.git","ssh_url":"git@github.com:lovell/libvips.git","clone_url":"https://github.com/lovell/libvips.git","svn_url":"https://github.com/lovell/libvips","homepage":"http://www.vips.ecs.soton.ac.uk","size":58081,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"lgpl-2.1","name":"GNU Lesser General Public License v2.1","spdx_id":"LGPL-2.1","url":"https://api.github.com/licenses/lgpl-2.1","node_id":"MDc6TGljZW5zZTEx"},"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"jcupitt:master","ref":"master","sha":"a4b89aa3701379d158e6f17a37262a0cd1936a4d","user":{"login":"jcupitt","id":580843,"node_id":"MDQ6VXNlcjU4MDg0Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/580843?v=4","gravatar_id":"","url":"https://api.github.com/users/jcupitt","html_url":"https://github.com/jcupitt","followers_url":"https://api.github.com/users/jcupitt/followers","following_url":"https://api.github.com/users/jcupitt/following{/other_user}","gists_url":"https://api.github.com/users/jcupitt/gists{/gist_id}","starred_url":"https://api.github.com/users/jcupitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcupitt/subscriptions","organizations_url":"https://api.github.com/users/jcupitt/orgs","repos_url":"https://api.github.com/users/jcupitt/repos","events_url":"https://api.github.com/users/jcupitt/events{/privacy}","received_events_url":"https://api.github.com/users/jcupitt/received_events","type":"User","site_admin":false},"repo":{"id":1291410,"node_id":"MDEwOlJlcG9zaXRvcnkxMjkxNDEw","name":"libvips","full_name":"jcupitt/libvips","owner":{"login":"jcupitt","id":580843,"node_id":"MDQ6VXNlcjU4MDg0Mw==","avatar_url":"https://avatars2.githubusercontent.com/u/580843?v=4","gravatar_id":"","url":"https://api.github.com/users/jcupitt","html_url":"https://github.com/jcupitt","followers_url":"https://api.github.com/users/jcupitt/followers","following_url":"https://api.github.com/users/jcupitt/following{/other_user}","gists_url":"https://api.github.com/users/jcupitt/gists{/gist_id}","starred_url":"https://api.github.com/users/jcupitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcupitt/subscriptions","organizations_url":"https://api.github.com/users/jcupitt/orgs","repos_url":"https://api.github.com/users/jcupitt/repos","events_url":"https://api.github.com/users/jcupitt/events{/privacy}","received_events_url":"https://api.github.com/users/jcupitt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jcupitt/libvips","description":"A fast image processing library with low memory needs.","fork":false,"url":"https://api.github.com/repos/jcupitt/libvips","forks_url":"https://api.github.com/repos/jcupitt/libvips/forks","keys_url":"https://api.github.com/repos/jcupitt/libvips/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jcupitt/libvips/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jcupitt/libvips/teams","hooks_url":"https://api.github.com/repos/jcupitt/libvips/hooks","issue_events_url":"https://api.github.com/repos/jcupitt/libvips/issues/events{/number}","events_url":"https://api.github.com/repos/jcupitt/libvips/events","assignees_url":"https://api.github.com/repos/jcupitt/libvips/assignees{/user}","branches_url":"https://api.github.com/repos/jcupitt/libvips/branches{/branch}","tags_url":"https://api.github.com/repos/jcupitt/libvips/tags","blobs_url":"https://api.github.com/repos/jcupitt/libvips/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jcupitt/libvips/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jcupitt/libvips/git/refs{/sha}","trees_url":"https://api.github.com/repos/jcupitt/libvips/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jcupitt/libvips/statuses/{sha}","languages_url":"https://api.github.com/repos/jcupitt/libvips/languages","stargazers_url":"https://api.github.com/repos/jcupitt/libvips/stargazers","contributors_url":"https://api.github.com/repos/jcupitt/libvips/contributors","subscribers_url":"https://api.github.com/repos/jcupitt/libvips/subscribers","subscription_url":"https://api.github.com/repos/jcupitt/libvips/subscription","commits_url":"https://api.github.com/repos/jcupitt/libvips/commits{/sha}","git_commits_url":"https://api.github.com/repos/jcupitt/libvips/git/commits{/sha}","comments_url":"https://api.github.com/repos/jcupitt/libvips/comments{/number}","issue_comment_url":"https://api.github.com/repos/jcupitt/libvips/issues/comments{/number}","contents_url":"https://api.github.com/repos/jcupitt/libvips/contents/{+path}","compare_url":"https://api.github.com/repos/jcupitt/libvips/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jcupitt/libvips/merges","archive_url":"https://api.github.com/repos/jcupitt/libvips/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jcupitt/libvips/downloads","issues_url":"https://api.github.com/repos/jcupitt/libvips/issues{/number}","pulls_url":"https://api.github.com/repos/jcupitt/libvips/pulls{/number}","milestones_url":"https://api.github.com/repos/jcupitt/libvips/milestones{/number}","notifications_url":"https://api.github.com/repos/jcupitt/libvips/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jcupitt/libvips/labels{/name}","releases_url":"https://api.github.com/repos/jcupitt/libvips/releases{/id}","deployments_url":"https://api.github.com/repos/jcupitt/libvips/deployments","created_at":"2011-01-25T13:15:00Z","updated_at":"2018-09-05T13:02:49Z","pushed_at":"2018-09-05T22:06:19Z","git_url":"git://github.com/jcupitt/libvips.git","ssh_url":"git@github.com:jcupitt/libvips.git","clone_url":"https://github.com/jcupitt/libvips.git","svn_url":"https://github.com/jcupitt/libvips","homepage":"https://jcupitt.github.io/libvips/","size":63871,"stargazers_count":2397,"watchers_count":2397,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":207,"mirror_url":null,"archived":false,"open_issues_count":66,"license":{"key":"lgpl-2.1","name":"GNU Lesser General Public License v2.1","spdx_id":"LGPL-2.1","url":"https://api.github.com/licenses/lgpl-2.1","node_id":"MDc6TGljZW5zZTEx"},"forks":207,"open_issues":66,"watchers":2397,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jcupitt/libvips/pulls/809"},"html":{"href":"https://github.com/jcupitt/libvips/pull/809"},"issue":{"href":"https://api.github.com/repos/jcupitt/libvips/issues/809"},"comments":{"href":"https://api.github.com/repos/jcupitt/libvips/issues/809/comments"},"review_comments":{"href":"https://api.github.com/repos/jcupitt/libvips/pulls/809/comments"},"review_comment":{"href":"https://api.github.com/repos/jcupitt/libvips/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jcupitt/libvips/pulls/809/commits"},"statuses":{"href":"https://api.github.com/repos/jcupitt/libvips/statuses/7ac034202087c840158b06f609d3c1ad85092bfb"}},"author_association":"CONTRIBUTOR","merged":false,"mergeable":true,"rebaseable":true,"mergeable_state":"clean","merged_by":null,"comments":5,"review_comments":0,"maintainer_can_modify":false,"commits":1,"additions":7,"deletions":3,"changed_files":1}}
{"actor":{"display_login":"lovell"}}