title: Why using dispatch_async is so slow compared to not using it at all?
body: <p>I wanted to know why my code runs much slower when I use  dispatch_async compared to when I don't use it at all. I'm trying to blur the edges of my UIImage by masking it and using UIGraphicsImageRenderer (Not sure if it's the most efficient way or not..)But when I don't use dispatch_async, It runs much much faster. Why is that? Here is my code and the result I get from my code. Any help is muchhhhh appreciated.</p>
  
  <p><a href="https://i.stack.imgur.com/Q7ISg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q7ISg.jpg" alt="enter image description here"></a></p>
  
  <pre><code>self.view.backgroundColor = [UIColor whiteColor];
       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                  UIImage* Img =  [UIImage imageNamed:@"1"];
                  UIImageView * imageview = [[UIImageView alloc]initWithImage:Img];
                  UIGraphicsImageRenderer * renderer = [[UIGraphicsImageRenderer alloc] initWithSize:Img.size];
  
                  UIBezierPath*path=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20,20,170,170) cornerRadius:5.0];
                  path.lineWidth = 20;
  
                  CAShapeLayer*shapeLayer = [CAShapeLayer new];
                  shapeLayer.path=path.CGPath;
  
                  [shapeLayer setFillColor:[UIColor redColor].CGColor];
                  [shapeLayer fillColor];
  
                  UIImage *shapeImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context){
                      [shapeLayer renderInContext: context.CGContext];}];
  
                  CIImage * shapeCimage = [[CIImage alloc] initWithImage:shapeImage];
                  CIFilter * gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
                  [gaussianBlurFilter setValue:shapeCimage forKey: @"inputImage"];
                  [gaussianBlurFilter setValue:@15 forKey:@"inputRadius"];
  
                  CIImage * blurredCIImage = [gaussianBlurFilter valueForKey:kCIOutputImageKey];
                  UIImage * blurredImage = [UIImage imageWithCIImage:blurredCIImage];
  
                  UIImageView *maskedImageView = [[UIImageView alloc]initWithImage:blurredImage];
                  maskedImageView.contentMode = UIViewContentModeScaleAspectFit;
                  maskedImageView.frame = imageview.frame;
                  imageview.layer.mask=maskedImageView.layer;
  
                  dispatch_async(dispatch_get_main_queue(), ^{
                      [self.view addSubview:imageview];
                  });
              });
  </code></pre>