Re: Concurrent loading of images ?
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