• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Concurrent loading of images ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Concurrent loading of images ?


  • Subject: Re: Concurrent loading of images ?
  • From: Gabriel Zachmann via Cocoa-dev <email@hidden>
  • Date: Tue, 12 May 2020 22:27:32 +0200

Thanks a million to everyone who has shared insights, hints, and advice on this.

I have restructured my code, so now I do the heavy lifting of loading images in
a serial dispatch queue.
However, there is still sometimes some stuttering visible in the animation of
the images.
Does anyone have an idea what might be causing it?

Here is the current structure of my code, given in sort of a pseudo-code:

-animateOneframe:
  // essentially, this gets called when the next image is to be displayed
  current_image_ = prefetched_image_;           // these are CGImageRef's
  dispatch_async( prefetch_queue_, ^{
            [self loadNextImage];
  } );
  create a new CALayer,
  assign the current_image_ as content,
  create an animation for the layer,
  add the layer to the layer hierarchy

In -loadNextImage, I am doing all the heavy lifting of loading images
(and the not-so-heavy), such as:
  prefetched_image_ = nil;
  CGImageSourceGetStatus
  CGImageSourceCopyPropertiesAtIndex
  CGImageSourceCreateThumbnailAtIndex
  imageByApplyingOrientation
  createCGImage
  prefetched_image_ = new image

(I know there is some potential race condition here, but that is not of concern
to me right now.)

Overall, I get the impression that it is "better" (less stuttering),
but sometimes there is still a stuttering in the animation when the app
makes a transition from one image to the next one.

How could that be?

Using Instruments, I can see this in the "heaviest stack trace" when CPU usage
is high in the main thread:

  41 CoreFoundation 3897.0  __CFRunLoopDoObservers
  40 CoreFoundation 3897.0
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
  39 QuartzCore 3896.0
CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
  38 QuartzCore 3896.0  CA::Transaction::commit()
  37 QuartzCore 3895.0  CA::Context::commit_transaction(CA::Transaction*,
double)
  36 QuartzCore 3895.0  CA::Layer::prepare_commit(CA::Transaction*)
  35 QuartzCore 3895.0  CA::Render::prepare_image(CGImage*, CGColorSpace*,
unsigned int, double)
  34 QuartzCore 3895.0  CA::Render::copy_image(CGImage*, CGColorSpace*,
unsigned int, double, double)
  33 QuartzCore 3895.0  CA::Render::(anonymous
namespace)::create_image_by_rendering(CGImage*, CGColorSpace*, unsigned int,
double, CA::Render::ImageCopyType)

Are these functions the culprits? How can I make them get executed in the
background?


All insights will be highly appreciated.

Best regards, Gabriel

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Concurrent loading of images ?
      • From: Alex Zavatone via Cocoa-dev <email@hidden>
References: 
 >Concurrent loading of images ? (From: Gabriel Zachmann via Cocoa-dev <email@hidden>)
 >Re: Concurrent loading of images ? (From: Jens Alfke via Cocoa-dev <email@hidden>)
 >Re: Concurrent loading of images ? (From: Rob Petrovec via Cocoa-dev <email@hidden>)
 >Re: Concurrent loading of images ? (From: Gabriel Zachmann via Cocoa-dev <email@hidden>)
 >Re: Concurrent loading of images ? (From: Jens Alfke via Cocoa-dev <email@hidden>)

  • Prev by Date: Re: Concurrent loading of images ?
  • Next by Date: Re: Concurrent loading of images ?
  • Previous by thread: Re: Concurrent loading of images ?
  • Next by thread: Re: Concurrent loading of images ?
  • Index(es):
    • Date
    • Thread