Speed up getpixel() and get_flattened_data() - #9881
Open
akx wants to merge 2 commits into
Open
Conversation
* Build N-tuples by hand instead of Py_BuildValue parsing format strings over and over * Tell the Python GC that the returned tuple contains no objects that may cause cycles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Came up as a side-effect of #9292 + https://github.com/akx/Pillow/pull/13/changes#r3819140811. Doesn't change the memory price of
get_flattened_data()though.Locally (pay no heed to the benchmarks' commit IDs; this final version has less redundant mode tests and as such, different commits):
Something that isn't necessarily captured by the benchmark is the
PyObject_GC_UnTrackchange; since we know that these tuples (immutable, as tuples are) will only contain 8-bit integers (and as an aside, CPython has likely returned cached small-integer references), we can tell the GC to not bother peeking inside them to see if there are cycles. This means that the next GC afterget_flattened_datawill not need to do that itself (it does need to do it for thetuple()cast fromget_flattened_dataonce though).