Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazily use ImageFileDirectory_v1 values from Exif #4031
Lazily use ImageFileDirectory_v1 values from Exif #4031
Changes from 1 commit
0b405c8
f3ed44a
ef16cb8
5a66877
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main difference is that
getexif
fromImage
class does not cache the parsed Exif tags.So this call is done and forget when the user will need it.
This is not what we should expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following, sorry. Yes, using
_getexif
would create a cache of the parsed exif tags, but it would also iterate over all the values.From my understanding, the point of these PRs is to reduce operations on load to potentially increase speed - we don't need to work out all of the EXIF values when a user might not even be interested in them. When JpegImagePlugin and MpoImagePlugin only need two EXIF values each, isn't decoding all the values overkill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the unclear review.
Yes, calling
getexif
is better, but right now, when reading an image, the_getexif
function is called, and the result is cached so that if the user called it once again, the computation will not happen a second time.This is not the case with
getexif
. If I trace a call toImage.open("my_image.jpg").getexif()
, then the dictionary loading and some decoding will happens twice.In my opinion, the
Exif
object should be stored into theImage
instance once loaded. And if the user needs to modify it, this object could be cloned.I hope it is clearer now 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, see what you think of this idea - I have pushed a commit that changes
im.getexif()
so that it returns a shared instance of the Exif class, meaning thatgetexif
decoding of EXIF values is now cached. This actually makes the_getexif
"parsed_exif" cache largely redundant, because_getexif
usesgetexif
, so I have removed that. Hopefully, that should make all scenarios faster.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice now :) Iterating 1000 times over an image (
open().getexif()
), I go from 18.0s to 8.11s. Confirmed by%timeit
in IPython, going from 3.69ms per loop to 1.68ms per loop.The last step (for me) is to get rid of
_fixup_dict
call of the tag 0x8769, but this should be in another PR.