3

A call to GCContextDrawImage turned out to be a bottleneck in my Mac OS X application, especially on retina screens. I managed to mitigate it somewhat by Avoiding colorspace transformations when blitting, Mac OS X 10.11 SDK, but it still seems to be slower than I would expect it to be.

When investigating the stack dump with Instruments I noticed that a lot of time was spent in two functions with highly suspicious names, vImageDebug_CheckDestBuffer which is calling into _ERROR_Buffer_Write__Too_Small_For_Arguments_To_vImage__CheckBacktrace. See the the full stack dump below.

This seems to me like some sort of debug assertion? Am I running a debug version of the vImage library without realising it? Is there something I can do to stop these functions from sucking up all my precious cycles?

Stack trace captured with Instruments

Community
  • 1
  • 1
finalman
  • 774
  • 5
  • 14
  • If I recall correctly, the functions just touch the first and last byte of the image to make sure it is there, so should not be taking much time. The idea is if the buffer is missing or too small, it will crash in a well named function pointing out your error. That it is showing up in a profiler suggests either the profiler is deeply confused about the backtrace or there is something quite unhappy about the buffer. Cache inhibited? Paged out? – Ian Ollmann Dec 03 '19 at 05:56

2 Answers2

1

The performance problem was solved by making sure the beginning of the pixel data in each scan line of the source bitmap is aligned to 16 bytes. Doing this seems to make the image drawing considerably faster. Presumably this happens by default if you allocate a new image, but we wrapped a CGImage around an existing pixel buffer which wasn't aligned.

finalman
  • 774
  • 5
  • 14
  • 1
    VImageBuffer_Init will do this sort of alignment. It also attempts to size things to avoid false aliasing stalls from successive rows. – Ian Ollmann Mar 08 '21 at 16:46
0

What about a graphics context (first parameter)? Do you pass it from other thread? What if you will get context in main thread, then draw image also in main thread?

menangen
  • 145
  • 2
  • 8