{"action":"created","issue":{"url":"https://api.github.com/repos/hMatoba/Piexif/issues/27","repository_url":"https://api.github.com/repos/hMatoba/Piexif","labels_url":"https://api.github.com/repos/hMatoba/Piexif/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/hMatoba/Piexif/issues/27/comments","events_url":"https://api.github.com/repos/hMatoba/Piexif/issues/27/events","html_url":"https://github.com/hMatoba/Piexif/issues/27","id":192773266,"number":27,"title":"piexifをより速くする","user":{"login":"metv","id":19845913,"avatar_url":"https://avatars.githubusercontent.com/u/19845913?v=3","gravatar_id":"","url":"https://api.github.com/users/metv","html_url":"https://github.com/metv","followers_url":"https://api.github.com/users/metv/followers","following_url":"https://api.github.com/users/metv/following{/other_user}","gists_url":"https://api.github.com/users/metv/gists{/gist_id}","starred_url":"https://api.github.com/users/metv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metv/subscriptions","organizations_url":"https://api.github.com/users/metv/orgs","repos_url":"https://api.github.com/users/metv/repos","events_url":"https://api.github.com/users/metv/events{/privacy}","received_events_url":"https://api.github.com/users/metv/received_events","type":"User","site_admin":false},"labels":[{"id":129111707,"url":"https://api.github.com/repos/hMatoba/Piexif/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-01T07:32:20Z","updated_at":"2016-12-26T15:47:18Z","closed_at":"2016-12-26T15:47:18Z","body":"問題ではありませんけどコメントがあります。今は私のプロジェクトにpyexiv2を使っています。しかしpyexiv2はPython2だけです。その上にpure Pythonではありません。piexifの方がいいと思います。\r\n\r\nEXIFを読むことだけがほしいです。\r\n\r\nそれでpiexifを試みています。小さいJPGでpiexifの方がpyexiv2より速いです。しかし大きい(10MB)のJPGでpiexifはとても遅いです。例えば、10000の大きいJPGを読むことはpyexiv2 9秒けどpiexifは79秒でした。残念！\r\n\r\ncProfileで調べました。遅いものは_load.pyのf.read() です。EXIFだけについて興味があるのに、何時も全部のファイルを読みます。それで修正しました:\r\n\r\n\r\n```\r\n_load.py:\r\n\r\nclass _ExifReader(object):\r\n    def __init__(self, data):\r\n        filename = data[:] # Save off the file name\r\n        if data[0:2] == b\"\\xff\\xd8\":  # JPEG\r\n[...]\r\n        else:\r\n            try:\r\n                with open(data, 'rb') as f:\r\n                    data = f.read(80000) # 80000 found by experiment\r\n            except:\r\n                raise ValueError(\"Got invalid value.\")\r\n            if data[0:2] == b\"\\xff\\xd8\":  # JPEG\r\n                segments = split_into_segments(data)\r\n\r\n                if (segments == 'Retry'): # We need more than the first 80000 bytes so read whole file\r\n                    try:\r\n                        with open(filename, 'rb') as f:\r\n                            data = f.read()\r\n                    except:\r\n                        raise ValueError(\"Got invalid value.\")\r\n                    segments = split_into_segments(data) # End modification\r\n[...]\r\n_common.py:\r\n# Add code to check whether we have a problem because we only read the first 80000 bytes.\r\n        if (head >= len(data)):\r\n          if (len(data) > 80000):\r\n            raise ValueError(\"Wrong JPEG data.\")\r\n          else:\r\n            segments = \"Retry\"\r\n            break\r\n```\r\n\r\n私にいいです。その修正でpiexifはとても早くなりました：2万写真は\r\npiexif: 10秒\r\npyexiv2: 25秒\r\n\r\n凄い!exifreadなどはpiexifとpyexiv2より遅いです。\r\n\r\n多分将来piexifは『読むことだけ』の速い_loadread()のAPIをもらいます。\r\n\r\nどうもあがとうございます。"},"comment":{"url":"https://api.github.com/repos/hMatoba/Piexif/issues/comments/269221634","html_url":"https://github.com/hMatoba/Piexif/issues/27#issuecomment-269221634","issue_url":"https://api.github.com/repos/hMatoba/Piexif/issues/27","id":269221634,"user":{"login":"hMatoba","id":4497270,"avatar_url":"https://avatars.githubusercontent.com/u/4497270?v=3","gravatar_id":"","url":"https://api.github.com/users/hMatoba","html_url":"https://github.com/hMatoba","followers_url":"https://api.github.com/users/hMatoba/followers","following_url":"https://api.github.com/users/hMatoba/following{/other_user}","gists_url":"https://api.github.com/users/hMatoba/gists{/gist_id}","starred_url":"https://api.github.com/users/hMatoba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hMatoba/subscriptions","organizations_url":"https://api.github.com/users/hMatoba/orgs","repos_url":"https://api.github.com/users/hMatoba/repos","events_url":"https://api.github.com/users/hMatoba/events{/privacy}","received_events_url":"https://api.github.com/users/hMatoba/received_events","type":"User","site_admin":false},"created_at":"2016-12-26T15:47:18Z","updated_at":"2016-12-26T15:47:18Z","body":"Done."}}
{"actor":{"display_login":"hMatoba"}}