SlideShare une entreprise Scribd logo
1  sur  14
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

Contenu connexe

Tendances

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis 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 MultithreadingMatsuo and Tsumura lab.
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)Hiroki Mizuno
 
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-autofdoKim Phillips
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory ManagementAlan Uthoff
 
Python opcodes
Python opcodesPython opcodes
Python opcodesalexgolec
 
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 AssistantNilhcem
 
openFrameworks 007 - utils
openFrameworks 007 - utilsopenFrameworks 007 - utils
openFrameworks 007 - utilsroxlu
 
Translating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptTranslating Classic Arcade Games to JavaScript
Translating Classic Arcade Games to JavaScriptnorbert_kehrer
 
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
 

Tendances (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
 

En vedette

Resume template ways of resume writing
Resume template   ways of resume writingResume template   ways of resume writing
Resume template ways of resume writingAlan Cruize
 
2014 st. mary's presentation 1
2014 st. mary's presentation 12014 st. mary's presentation 1
2014 st. mary's presentation 1emolnar2
 
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
 

En vedette (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
 

Similaire à 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 Tutorialantiw
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Optimize CollectionView Scrolling
Optimize CollectionView ScrollingOptimize CollectionView Scrolling
Optimize CollectionView ScrollingAndrea 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 .netStephen 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-senseBen 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 DataAutodesk
 
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 2019DanielJalkut
 
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 2015Ben 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 anymoreRemy Sharp
 
CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41CS101- Introduction to Computing- Lecture 41
CS101- Introduction to Computing- Lecture 41Bilal Ahmed
 

Similaire à 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
 

Dernier

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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