Skip to content
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

Major (non-linear) performance regression with ImageDraw.polygon #5700

Closed
ntninja opened this issue Sep 1, 2021 · 4 comments
Closed

Major (non-linear) performance regression with ImageDraw.polygon #5700

ntninja opened this issue Sep 1, 2021 · 4 comments
Labels
Anaconda Issues with Anaconda's Pillow Performance

Comments

@ntninja
Copy link

ntninja commented Sep 1, 2021

What did you do?

See the sample program below for a minimal test case – it simply draws a polygon from a list of input coordinates.

What did you expect to happen?

Time taken to render the polygon line to be linear (and very small) even for 100'000s of points.

What actually happened?

Apparently in any Pillow version after 7.0.0 the time taken to draw coordinate lists appears to increase non-linear with the number of input coordinates. When processing larger input files we regularily end up with 100'000s or perhaps even 1'000'000s points to be (nicely) drawn by Pillow for file visualization. With 7.0.0 this was no problem, with drawing times hardly ever exceeding a second at most, but since 7.1.1 (and likely also 7.1.0) the drawing suddenly turned into the slowest part of our production pipeline for larger files.

What are your OS, Python and Pillow versions?

  • OS: Linux x86-64 with Conda
  • Python: 3.6 or 3.9
  • Pillow: 7.1.1 (and any later version, 7.1.0 is likely affected too ) – using conda-forge build

Very likely related: #4333

#!/usr/bin/env python3                                                              
import json                                                                         
                                                                                    
from PIL import Image, ImageDraw, ImageFont                                         
                                                                                    
oversampling_factor = 2                                                             
width = 707                                                                         
height = 90                                                                         
scolor = "#000000"                                                                  
background_color = "#FFFFFF"                                                        
                                                                                    
image = Image.new(                                                                  
    "RGB",                                                                          
    (width * oversampling_factor, height * oversampling_factor),                    
    background_color,                                                               
)                                                                                   
                                                                                    
draw = ImageDraw.Draw(image)                                                        
with open("pillow_slow_polygon_coords.json", "r") as f:                             
    draw.polygon(json.load(f), scolor)                                              
                                                                                    
image = image.resize((width, height), Image.ANTIALIAS)                              
image.save("pillow_slow_polygon_output.png")

Referenced JSON file: pillow_slow_polygon_coords.json – this is audio waveform data but the issue is likely the same for other data as only the number of coordinates appear to matter.

@radarhere
Copy link
Member

Testing, yes, #4333 is responsible for this.

@radarhere
Copy link
Member

I've created PR #5835 to resolve this, by reverting #4333 when drawing without transparency, as is happening in this issue.

@radarhere
Copy link
Member

Resolved by #5835

@ntninja
Copy link
Author

ntninja commented Nov 17, 2021

Thank you! 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anaconda Issues with Anaconda's Pillow Performance
Projects
None yet
Development

No branches or pull requests

3 participants