ImageMagick / ImageMagick/ImageMagick

MagickWand: significant performance drop when stroking paths with scale > 1

Open
#8,443 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.5k
Forks
1.7k
Avg merge
10h 17m
Merged PRs (30d)
28

Description

ImageMagick version

7.1.1-46

Operating system

Linux

Operating system, version and so on

Ubuntu 22.04 LTS

Description

We encountered some very strange behavior when drawing geometries.

Here is an example of what we want to draw (50_000 circles):
Image

This works satisfactorily fast (about 4 seconds) in three out of four cases. But when the circle has a stroke and the scaling in the transformation is greater than one, there is a sharp drop in performance—drawing takes 44 seconds.
Image

The situation is even worse if the circle is drawn using a path (arc with angle=2*PI). In this case, drawing 50,000 circles will not complete.

Image
Steps to Reproduce

These images are automatically generated by our library. The MVG is dumped using the DrawGetVectorGraphics function.

DrawCircle test:

  1. Unzip circle_50000.zip
  2. Run magick -size 600x400 mvg:./circle_50000.mvg circle_50000.png
    Result: conversion takes acceptable time, like ~5 seconds (could be better, though?)
  3. Unzip circle_50000@2x.zip
  4. Run magick -size 1200x800 mvg:./circle_50000@2x.mvg circle_50000@2x.png
    Result: conversion takes unacceptable 40+ seconds, yet the only difference is the affine 2 0 0 2 0 0 at the beginning of the file.

DrawPath* test:

  1. Unzip path_10000.zip
  2. Run magick -size 800x400 mvg:./path_10000.mvg path_10000.png
    Result: converted in zero seconds.
  3. Unzip path_10000@2x.zip
  4. Run magick -size 1200x800 mvg:./path_10000@2x.mvg path_10000@2x.png
    Result: conversion takes unacceptable 5 seconds to draw just 10_000 circles, yet the only difference is the affine 2 0 0 2 0 0 at the beginning of the file.
Images

circle_50000.zip
circle_50000@2x.zip
path_10000.zip
path_10000@2x.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the slowdown with the supplied circle_50000, circle_50000@2x, path_10000, and path_10000@2x MVG archives using the documented magick commands. Start by comparing rendering with and without the affine scale and trace the MagickWand drawing path handling. Done means scaled stroked circles and paths render without the reported severe performance regression, with benchmarks covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli, computer-graphics, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.