SlideShare a Scribd company logo
GCD in Action
• three practical use cases •
@mindbrix
Nigel Timothy Barber
• Blocks
• Queues
• Sources
• Groups
• Semaphores
Grand Central Dispatch
http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html
@mindbrix
OpenGL + UIScrollView
problem: OpenGL rendering on main thread
breaks UIScrollView timing loop
aim: smooth, zoomable canvas
solution: Grand Central Dispatch...
@mindbrix
dispatch_queue_t glQueue = dispatch_queue_create( "uk.co.mindbrix.glQueue", DISPATCH_QUEUE_SERIAL );
dispatch_semaphore_t frameRenderingSemaphore = dispatch_semaphore_create( 1 );
-(void)drawViewQueued:(CADisplayLink *)displayLink
{
if( dispatch_semaphore_wait( frameRenderingSemaphore, DISPATCH_TIME_NOW ) != 0 )
{
return;
}
dispatch_async( glQueue,
^{
[ EAGLContext setCurrentContext: m_context ];
[ self render ];
dispatch_semaphore_signal( frameRenderingSemaphore );
});
}
OpenGL + UIScrollView
@mindbrix
OpenGL + UIScrollView
@mindbrix
UITableViewCell
problem: recursive pattern and PDF
UIImage rendering is slow
aim: smooth thumbnail scrolling
solution: Grand Central Dispatch...
@mindbrix
-(void)loadTableCellImage:(VSNarrowCell *)cell fromURL:(NSURL *)url atSize:(CGSize)size withPlaceholder:(UIImage *)placeholder
{
if(![ cell.imageURL isEqual:url ] || ( cell.imageView == nil ))
{
cell.imageView.image = placeholder;
cell.imageURL = url;
dispatch_async( renderingQueue, ^()
{
UIImage *image = nil;
if([[ url pathExtension ] caseInsensitiveCompare:@"pdf" ] == NSOrderedSame )
{
image = [ UIImage imageWithPDFURL:url atSize:size ];
}
else
{
image = [ UIImage imageWithPathTreeURL:url atSize:size ];
}
dispatch_async( dispatch_get_main_queue(), ^()
{
if([ cell.imageURL isEqual:url ])
{
cell.imageView.image = image;
}
});
});
}
}
UITableViewCell
@mindbrix
UITableViewCell
@mindbrix
UITableViewCell
@mindbrix
UILabel + NSAttributedString
problem: slow UILabel drawing makes the
main loop stutter
aim: continuous attributed label updates
solution: Grand Central Dispatch...
@mindbrix
UILabel + NSAttributedString
-(void)drawAfterUpdate:(void (^)(void))updateBlock
{
if( self.view && updateBlock )
{
if (dispatch_semaphore_wait( _renderingSemaphore, DISPATCH_TIME_NOW ) != 0 )
{
return;
}
dispatch_async( _renderingQueue, ^()
{
updateBlock();
UIImage *image = [ self imageFromView:self.view ];
dispatch_async( dispatch_get_main_queue(), ^()
{
self.image = image;
});
dispatch_semaphore_signal( _renderingSemaphore );
});
}
}
-(id)initWithView:(UIView *)view
{
self = [ super initWithFrame:view.frame ];
if( self )
{
self.view = view;
if( view.superview )
{
[ view removeFromSuperview ];
}
_renderingSemaphore = dispatch_semaphore_create( 1 );
_renderingQueue = dispatch_queue_create( "uk.co.mindbrix.NTBProxyImageView",
DISPATCH_QUEUE_SERIAL );
}
return self;
}
[ self.valueLabelProxy drawAfterUpdate:^{
if([ self.valueLabel respondsToSelector:@selector(setAttributedText:)])
{
NSString *HTML = @"<font name='Helvetica' color='#FFFFFF' size='12'><b>Hello, World</b></
font>;
self.valueLabel.attributedText = [ NSAttributedString stringFromHTML: HTML ];
}
else
{
self.valueLabel.text = @"Hello, World";
}
}];
self.valueLabel = [[ UILabel alloc ] initWithFrame:valueLabelFrame ];
self.valueLabel.backgroundColor = [ UIColor clearColor ];
self.valueLabel.textColor = [ UIColor whiteColor ];
self.valueLabel.textAlignment = NSTextAlignmentCenter;
[ rootView addSubview:self.valueLabel ];
[ self.valueLabel release ];
self.valueLabelProxy = [[ NTBProxyImageView alloc ] initWithView:self.valueLabel ];
[ rootView addSubview:self.valueLabelProxy ];
[ self.valueLabelProxy release ];
NTBProxyImageView NTBProxyImageView
@mindbrix
UILabel + NSAttributedString
@mindbrix
Links
@mindbrix
https://github.com/mindbrix/UIImage-PDF
UIImage+PDF
https://gist.github.com/mindbrix/5832707
NTBProxyImageView
GCD in Action
• three practical use cases •
@mindbrix
Nigel Timothy Barber

More Related Content

What's hot

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
Luis Vendrame
 
A Speculative Technique for Auto-Memoization Processor with Multithreading
A Speculative Technique for Auto-Memoization Processor with MultithreadingA Speculative Technique for Auto-Memoization Processor with Multithreading
A Speculative Technique for Auto-Memoization Processor with Multithreading
Matsuo and Tsumura lab.
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
Domenic Denicola
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)Hiroki Mizuno
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
Mohammad Shaker
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
Mr. Vengineer
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
Hanokh Aloni
 
Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1
Raphael Marques
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Dimitrios Platis
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
Kim Phillips
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
Python opcodes
Python opcodesPython opcodes
Python opcodes
alexgolec
 
Home Automation with Android Things and the Google Assistant
Home Automation with Android Things and the Google AssistantHome Automation with Android Things and the Google Assistant
Home Automation with Android Things and the Google Assistant
Nilhcem
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
roxlu
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScript
norbert_kehrer
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
Manoj Kumar
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Daniel Luxemburg
 
Mini-curso JavaFX Aula2
Mini-curso JavaFX Aula2Mini-curso JavaFX Aula2
Mini-curso JavaFX Aula2
Raphael Marques
 

What's hot (20)

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
A Speculative Technique for Auto-Memoization Processor with Multithreading
A Speculative Technique for Auto-Memoization Processor with MultithreadingA Speculative Technique for Auto-Memoization Processor with Multithreading
A Speculative Technique for Auto-Memoization Processor with Multithreading
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
 
Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1Mini-curso JavaFX Aula1
Mini-curso JavaFX Aula1
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 
C c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdoC c++-meetup-1nov2017-autofdo
C c++-meetup-1nov2017-autofdo
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
Python opcodes
Python opcodesPython opcodes
Python opcodes
 
Home Automation with Android Things and the Google Assistant
Home Automation with Android Things and the Google AssistantHome Automation with Android Things and the Google Assistant
Home Automation with Android Things and the Google Assistant
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utils
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScript
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
cpp_sample
cpp_samplecpp_sample
cpp_sample
 
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
 
Mini-curso JavaFX Aula2
Mini-curso JavaFX Aula2Mini-curso JavaFX Aula2
Mini-curso JavaFX Aula2
 

Viewers also liked

Resume template ways of resume writing
Resume template   ways of resume writingResume template   ways of resume writing
Resume template ways of resume writing
Alan Cruize
 
2014 st. mary's presentation 1
2014 st. mary's presentation 12014 st. mary's presentation 1
2014 st. mary's presentation 1
emolnar2
 
Athlete Recruiting Division I Requirements (Section 4 of 11)
Athlete Recruiting Division I Requirements (Section 4 of 11)Athlete Recruiting Division I Requirements (Section 4 of 11)
Athlete Recruiting Division I Requirements (Section 4 of 11)
athletebuilder
 
Шуфлядка
ШуфлядкаШуфлядка
Шуфлядка
Slashman
 
Top 50 Recruiting Tips
Top 50 Recruiting TipsTop 50 Recruiting Tips
Top 50 Recruiting Tips
Patosha Jeffery
 
McKinsey Resume Sample
McKinsey Resume SampleMcKinsey Resume Sample
McKinsey Resume Sample
ConsultingFact.com
 

Viewers also liked (6)

Resume template ways of resume writing
Resume template   ways of resume writingResume template   ways of resume writing
Resume template ways of resume writing
 
2014 st. mary's presentation 1
2014 st. mary's presentation 12014 st. mary's presentation 1
2014 st. mary's presentation 1
 
Athlete Recruiting Division I Requirements (Section 4 of 11)
Athlete Recruiting Division I Requirements (Section 4 of 11)Athlete Recruiting Division I Requirements (Section 4 of 11)
Athlete Recruiting Division I Requirements (Section 4 of 11)
 
Шуфлядка
ШуфлядкаШуфлядка
Шуфлядка
 
Top 50 Recruiting Tips
Top 50 Recruiting TipsTop 50 Recruiting Tips
Top 50 Recruiting Tips
 
McKinsey Resume Sample
McKinsey Resume SampleMcKinsey Resume Sample
McKinsey Resume Sample
 

Similar to GCD in Action

I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)
Katsumi Kishikawa
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
antiw
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Optimize CollectionView Scrolling
Optimize CollectionView ScrollingOptimize CollectionView Scrolling
Optimize CollectionView Scrolling
Andrea Prearo
 
Standford 2015 week6
Standford 2015 week6Standford 2015 week6
Standford 2015 week6
彼得潘 Pan
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
Stephen Lorello
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
DroidConTLV
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
Ben Lin
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatchcqtt191
 
Forge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design DataForge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design Data
Autodesk
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
GeeksLab Odessa
 
Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)
Jorge Maroto
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019
DanielJalkut
 
Android design and Custom views
Android design and Custom views Android design and Custom views
Android design and Custom views Lars Vogel
 
Grand Central Dispatch - iOS Conf SG 2015
Grand Central Dispatch - iOS Conf SG 2015Grand Central Dispatch - iOS Conf SG 2015
Grand Central Dispatch - iOS Conf SG 2015
Ben Asher
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
Bilal Ahmed
 

Similar to GCD in Action (20)

I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)I phone勉強会 (2011.11.23)
I phone勉強会 (2011.11.23)
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
Optimize CollectionView Scrolling
Optimize CollectionView ScrollingOptimize CollectionView Scrolling
Optimize CollectionView Scrolling
 
Standford 2015 week6
Standford 2015 week6Standford 2015 week6
Standford 2015 week6
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Forge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design DataForge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design Data
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 
Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)Synchronizing without internet - Multipeer Connectivity (iOS)
Synchronizing without internet - Multipeer Connectivity (iOS)
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019Daniel Jalkut - dotSwift 2019
Daniel Jalkut - dotSwift 2019
 
Android design and Custom views
Android design and Custom views Android design and Custom views
Android design and Custom views
 
Grand Central Dispatch - iOS Conf SG 2015
Grand Central Dispatch - iOS Conf SG 2015Grand Central Dispatch - iOS Conf SG 2015
Grand Central Dispatch - iOS Conf SG 2015
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

GCD in Action

  • 1. GCD in Action • three practical use cases • @mindbrix Nigel Timothy Barber
  • 2. • Blocks • Queues • Sources • Groups • Semaphores Grand Central Dispatch http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html @mindbrix
  • 3. OpenGL + UIScrollView problem: OpenGL rendering on main thread breaks UIScrollView timing loop aim: smooth, zoomable canvas solution: Grand Central Dispatch... @mindbrix
  • 4. dispatch_queue_t glQueue = dispatch_queue_create( "uk.co.mindbrix.glQueue", DISPATCH_QUEUE_SERIAL ); dispatch_semaphore_t frameRenderingSemaphore = dispatch_semaphore_create( 1 ); -(void)drawViewQueued:(CADisplayLink *)displayLink { if( dispatch_semaphore_wait( frameRenderingSemaphore, DISPATCH_TIME_NOW ) != 0 ) { return; } dispatch_async( glQueue, ^{ [ EAGLContext setCurrentContext: m_context ]; [ self render ]; dispatch_semaphore_signal( frameRenderingSemaphore ); }); } OpenGL + UIScrollView @mindbrix
  • 6. UITableViewCell problem: recursive pattern and PDF UIImage rendering is slow aim: smooth thumbnail scrolling solution: Grand Central Dispatch... @mindbrix
  • 7. -(void)loadTableCellImage:(VSNarrowCell *)cell fromURL:(NSURL *)url atSize:(CGSize)size withPlaceholder:(UIImage *)placeholder { if(![ cell.imageURL isEqual:url ] || ( cell.imageView == nil )) { cell.imageView.image = placeholder; cell.imageURL = url; dispatch_async( renderingQueue, ^() { UIImage *image = nil; if([[ url pathExtension ] caseInsensitiveCompare:@"pdf" ] == NSOrderedSame ) { image = [ UIImage imageWithPDFURL:url atSize:size ]; } else { image = [ UIImage imageWithPathTreeURL:url atSize:size ]; } dispatch_async( dispatch_get_main_queue(), ^() { if([ cell.imageURL isEqual:url ]) { cell.imageView.image = image; } }); }); } } UITableViewCell @mindbrix
  • 10. UILabel + NSAttributedString problem: slow UILabel drawing makes the main loop stutter aim: continuous attributed label updates solution: Grand Central Dispatch... @mindbrix
  • 11. UILabel + NSAttributedString -(void)drawAfterUpdate:(void (^)(void))updateBlock { if( self.view && updateBlock ) { if (dispatch_semaphore_wait( _renderingSemaphore, DISPATCH_TIME_NOW ) != 0 ) { return; } dispatch_async( _renderingQueue, ^() { updateBlock(); UIImage *image = [ self imageFromView:self.view ]; dispatch_async( dispatch_get_main_queue(), ^() { self.image = image; }); dispatch_semaphore_signal( _renderingSemaphore ); }); } } -(id)initWithView:(UIView *)view { self = [ super initWithFrame:view.frame ]; if( self ) { self.view = view; if( view.superview ) { [ view removeFromSuperview ]; } _renderingSemaphore = dispatch_semaphore_create( 1 ); _renderingQueue = dispatch_queue_create( "uk.co.mindbrix.NTBProxyImageView", DISPATCH_QUEUE_SERIAL ); } return self; } [ self.valueLabelProxy drawAfterUpdate:^{ if([ self.valueLabel respondsToSelector:@selector(setAttributedText:)]) { NSString *HTML = @"<font name='Helvetica' color='#FFFFFF' size='12'><b>Hello, World</b></ font>; self.valueLabel.attributedText = [ NSAttributedString stringFromHTML: HTML ]; } else { self.valueLabel.text = @"Hello, World"; } }]; self.valueLabel = [[ UILabel alloc ] initWithFrame:valueLabelFrame ]; self.valueLabel.backgroundColor = [ UIColor clearColor ]; self.valueLabel.textColor = [ UIColor whiteColor ]; self.valueLabel.textAlignment = NSTextAlignmentCenter; [ rootView addSubview:self.valueLabel ]; [ self.valueLabel release ]; self.valueLabelProxy = [[ NTBProxyImageView alloc ] initWithView:self.valueLabel ]; [ rootView addSubview:self.valueLabelProxy ]; [ self.valueLabelProxy release ]; NTBProxyImageView NTBProxyImageView @mindbrix
  • 14. GCD in Action • three practical use cases • @mindbrix Nigel Timothy Barber