High CPU usage on macOS using COffscreenContext

A user interface toolkit mainly for audio plug-ins (VST, AudioUnit, etc).
Post Reply
yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

Hi,

I'm trying to diagnose high cpu usage on macOS with vstgui 4.4. My application is standalone using the plugguieditor. The problem seems to be with a COffscreenContext that I'm using as a ring buffer for a scrolling meter. I'm attaching a pic showing the part of the UI with the scrolling meter and some information from instruments. The scrolling meter that uses the COffsreenContext as a ring buffer is outlined in red in the picture.

I'm running the application on a i3 mac mini, but I also see high cpu using on my 2017 MacBook Pro. The same code runs very smoothly on my PC. Any ideas?

Also, would I be better off using a CBitmap as my ring buffer and drawing to it using CBitmapPixelAccess? It seems that if I want to use vstgui 4.5 or greater, this might be my only option as COffscreenContexts work differently from 4.5 and up.

Regards,
Rob
pic.png
You do not have the required permissions to view the files attached to this post.

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

After full days of optimizations and verifying that my UI is only updating the correct views, I'm still making no progress on this.

I'm trying to set a breakpoint in VSTGUI_NSView_drawRect from nsviewframe.mm to see what is actually being drawn by the system, but xcode refuses to break there. Any ideas how I can verify what rectangle the system is actually drawing?

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

Not sure if it helps, but here is how I'm creating my editor.

Code: Select all

    [self.window setFrame:frame display:YES animate:YES];
    
    NSView* view = self.window.contentView;
    CRect r (0, 0, view.bounds.size.width, view.bounds.size.height);

    [[self window] setContentAspectRatio:NSMakeSize(view.bounds.size.width, view.bounds.size.height)];    
    
    editor = new Editor((__bridge void*)view);

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

Would implementing that view as a COoenGLView help?

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

I'm going to go ahead and say the OpenGLView is the way to go. I cut and pasted some code from the OpenGLView example in the tests folder, and the 3D pyramid run smoothly on macOS, adding almost no additional CPU load.

Arne Scheffler
Posts: 383
Joined: Mon Jun 20, 2016 7:53 am

Re: High CPU usage on macOS using COffscreenContext

Post by Arne Scheffler »

Hi,
you can try to put your view with the "scrolling meter" into a CLayeredViewContainer and see if it helps.

Cheers,
Arne

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

Thank-you. I will try that.

yeahtuna
Posts: 28
Joined: Tue Jun 21, 2016 10:41 pm

Re: High CPU usage on macOS using COffscreenContext

Post by yeahtuna »

Hi Arne,

Putting the view in a CLayeredViewContainer did not improve performance. I'm seeing significant performance issues when using COffscreenContexts on macOS / iOS in general. Drawing with OGL is by far the most efficient, but even redrawing the entire scrolling view from scratch each time (which is about 300 line segments) is significantly more efficient, at least in terms of CPU, than using a COffscreenContext as a ring buffer.

Regards,
Rob

User avatar
pongasoft
Posts: 118
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: High CPU usage on macOS using COffscreenContext

Post by pongasoft »

I am not sure if it will be 100% relevant, but for my vst plugin, I use a COfffScreenContext to generate a bitmap (which is then cached) and the bitmap is drawn into the view. I have no performance problems (on macOS).

Here is the code (source: https://github.com/pongasoft/vst-sam-sp ... ew.cpp#L63)

Code: Select all

void SampleDisplayView::generateBitmap(SampleData const &iSampleData)
{
  // TODO: optimization: load -> mono -> compute summary at the same time

  auto buffers = iSampleData.load(*fSampleRate);
  if(buffers && buffers->hasSamples())
  {
    //buffers = buffers->toMono();

    auto context = COffscreenContext::create(getFrame(), getWidth(), getHeight(), getFrame()->getScaleFactor());

    fBitmap = Waveform::createBitmap(context,
                                     buffers.get(),
                                     {getWaveformColor(), getWaveformAxisColor(), 2, getMargin()});
  }
  else
    fBitmap = nullptr;
}
The content is pretty complicated because it is the waveform of a sample

Yan

Post Reply