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

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Dernier (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

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