SlideShare a Scribd company logo
1 of 18
Dynamic Language Performanceor How I Learned to Love Metaprogramming W. Kevin Hazzard, C# MVP NoVA Code Camp October 2009
Agenda MetaObjects and MetaProgramming Dynamic Language Runtime Architecture The dynamic keyword in C# 4 The CallSite<T> Class The CSharpRuntimeBinder DynamicMetaObjects Adaptive Inline Caching Demonstrations Fluent XML Parsing Performance of Python to C# Integration
Metaobject Visualization Metaobject control create invoke Backing Objects Users and programs interact with metaobjects, not directly with their backing objects.
DLR Architecture
The dynamic Keyword [Dynamic] objectDX = someFunction(); dynamic DX = someFunction(); DX( ‘A’ ); DX.Foo( 1 ); DX.Bar = ‘X’; int V = DX.Baz; DX[0] = 100; string S = DX[0]; // invoke the object // invoke the Foo member // set the Bar member // convert the Baz member to integer // set index 0 to 100 // convert index 0 to string Is dynamic a new type? No The dynamic type is totally static  This type is a signal to the compiler to perform late binding
Let's Stop and Reflect class Program{   dynamic Jabberwocky( dynamicarg ) { return arg.foo();   } } [return: Dynamic] object Jabberwocky( [Dynamic] objectarg ) { if (<Jabberwocky>o__SiteContainer2.<>p__Site3 == null) {     <Jabberwocky>o__SiteContainer2.<>p__Site3 =  CallSite<Func<CallSite, object, object>>.Create( newCSharpInvokeMemberBinder( CSharpCallFlags.None,            "foo", typeof( Program ), null,  newCSharpArgumentInfo[] {  newCSharpArgumentInfo( CSharpArgumentInfoFlags.None, null ) } ) );   } return <Jabberwocky>o__SiteContainer2.<>p__Site3.Target(     <Jabberwocky>o__SiteContainer2.<>p__Site3, arg ); }
The CallSite<T> Class In the System.Runtime.CompilerServices namespace Created and managed in a static container class for each venue Key members: Create – creates and assign a binder Target – a delegate that invokes the binder Binder – connects an appropriate metaobject to the underlying call implementation
The CSharpRuntimeBinder What might these describe? Semantic Checker Symbol Table Expression Tree Creator Expression Factory Context Info Controller Dispatcher
What is a metaobject? An object that: May contain info on the: Creates Controls Invokes Describes Implements Interfaces of Type of Methods of Fields of Properties of Attributes of … another object
The DynamicMetaObject Class ,[object Object]
All expression tree-orientedBindCreateInstance BindBinaryOperation BindUnaryOperation BindConvert BindDeleteMember BindDeleteIndex BindInvoke BindInvokeMember BindGetMember BindSetMember BindGetIndex BindSetIndex
IDynamicMetaObjectProvider public interface IDynamicMetaObjectProvider {     DynamicMetaObject GetMetaObject(         Expression parameter ); } Pattern for implementing a custom metaobject The returned DynamicMetaObject must implement all twelve binding methods (and more) Lots of Expression Tree knowledge is required Not a trivial exercise
DynamicObject to the rescue! public class DynamicObject : IDynamicMetaObjectProvider {   protected DynamicObject(); public virtual DynamicMetaObjectGetMetaObject(...); public virtual boolTryBinaryOperation(...); public virtual boolTryConvert(...); public virtual boolTryCreateInstance(...); public virtual boolTryDeleteIndex(...); public virtual boolTryDeleteMember(...); public virtual boolTryGetIndex(...); public virtual boolTryGetMember(...); public virtual boolTryInvoke(...); public virtual boolTryInvokeMember(...); public virtual boolTrySetIndex(...); public virtual boolTrySetMember(...); public virtual boolTryUnaryOperation(...); }
Example – Fluent XML Parsing Wouldn't it be nice if we could read and write XML like a set of nested objects without deep knowledge of the XML DOM or LINQ to XML? <books pubdate="2009-06-15">   <book price="45.99" title="Surgery for Dummies">     <id isbn10="4389880339"/>     <authors>       <author>         <name>           <first>Mortimer</first>           <last>Snerdly</last>         </name>         <email address="mort@surgery.com"/>       </author>     </authors>   </book> </books> WriteLine( books.book[0].authors.author[0].name.first);
Fluent XML pARSING in C# Demonstration
Adaptive Inline Caching Each CallSite uses 3 levels of caching Level 0 – a dynamically generated delegate for some of the call patterns encountered at the site Level 1 – a read-only set of rules for all of the call patterns that the site has seen so far Level 2 – a read-only set of rules that spans multiple call sites
What about level 2 cache misses? A level 2 cache miss causes: The creation of a new rule The insertion of the new rule into the level 2 cache (on the ActionBinder) The insertion of the new rule into the level 1 cache (on the CallSite rule set) Possible insertion into the level 0 cache (on the CallSite dynamic delegate)
Performance ofPython to C# Integration Demonstration

More Related Content

What's hot

Basic vbscript for qtp
Basic vbscript for qtpBasic vbscript for qtp
Basic vbscript for qtpCuong Tran Van
 
Utilize Jericho HTML Parser to Resolve NCR Problem
Utilize Jericho HTML Parser to Resolve NCR ProblemUtilize Jericho HTML Parser to Resolve NCR Problem
Utilize Jericho HTML Parser to Resolve NCR ProblemGuo Albert
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScriptKeithMurgic
 
JavaScript Essentials for Ember development
JavaScript Essentials for Ember developmentJavaScript Essentials for Ember development
JavaScript Essentials for Ember developmentLeo Hernandez
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_scriptVijay Kalyan
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building BlocksCate Huston
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming LanguageRaghavan Mohan
 
polymorphism and virtual function
polymorphism and virtual functionpolymorphism and virtual function
polymorphism and virtual functionBhanuprataparya
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with GroovyDhaval Dalal
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operatorsVivek Kumar
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsAjax Experience 2009
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetHDR1001
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 

What's hot (20)

Basic vbscript for qtp
Basic vbscript for qtpBasic vbscript for qtp
Basic vbscript for qtp
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
 
Utilize Jericho HTML Parser to Resolve NCR Problem
Utilize Jericho HTML Parser to Resolve NCR ProblemUtilize Jericho HTML Parser to Resolve NCR Problem
Utilize Jericho HTML Parser to Resolve NCR Problem
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
JavaScript Essentials for Ember development
JavaScript Essentials for Ember developmentJavaScript Essentials for Ember development
JavaScript Essentials for Ember development
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
TypeScript, Now.
TypeScript, Now.TypeScript, Now.
TypeScript, Now.
 
Typescript
TypescriptTypescript
Typescript
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
polymorphism and virtual function
polymorphism and virtual functionpolymorphism and virtual function
polymorphism and virtual function
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 

Viewers also liked

Like Minds: Digital Journalism in 2008
Like Minds: Digital Journalism in 2008Like Minds: Digital Journalism in 2008
Like Minds: Digital Journalism in 2008Anthony Moor
 
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...Al Sargent
 
FDA: Food Additive Approval Process Followed for Aspartame
FDA:  Food Additive Approval Process Followed for AspartameFDA:  Food Additive Approval Process Followed for Aspartame
FDA: Food Additive Approval Process Followed for Aspartameswilsonmc
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010Kevin Hazzard
 
Instructional media services
Instructional media servicesInstructional media services
Instructional media serviceswcochenour
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL AzureKevin Hazzard
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data ValidationKevin Hazzard
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewAl Sargent
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#Kevin Hazzard
 
Algolia @ProductTank Paris #13 - Dec 2014
Algolia @ProductTank Paris #13 - Dec 2014Algolia @ProductTank Paris #13 - Dec 2014
Algolia @ProductTank Paris #13 - Dec 2014Gaëtan Gachet
 
Top Secret: GCHQ: The Art of Deception. Training for a New Generation of On...
Top Secret:  GCHQ:  The Art of Deception. Training for a New Generation of On...Top Secret:  GCHQ:  The Art of Deception. Training for a New Generation of On...
Top Secret: GCHQ: The Art of Deception. Training for a New Generation of On...swilsonmc
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersKevin Hazzard
 

Viewers also liked (18)

Sacha Baron Cohen
Sacha Baron CohenSacha Baron Cohen
Sacha Baron Cohen
 
Like Minds: Digital Journalism in 2008
Like Minds: Digital Journalism in 2008Like Minds: Digital Journalism in 2008
Like Minds: Digital Journalism in 2008
 
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...
Gartner IT Ops Summit 2015: Why Fast is not enough: App Monitoring in the Cus...
 
FDA: Food Additive Approval Process Followed for Aspartame
FDA:  Food Additive Approval Process Followed for AspartameFDA:  Food Additive Approval Process Followed for Aspartame
FDA: Food Additive Approval Process Followed for Aspartame
 
Presentation1qa
Presentation1qaPresentation1qa
Presentation1qa
 
The Big Picture
The Big PictureThe Big Picture
The Big Picture
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
 
Instructional media services
Instructional media servicesInstructional media services
Instructional media services
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
 
Sauce Labs Beta Program Overview
Sauce Labs Beta Program OverviewSauce Labs Beta Program Overview
Sauce Labs Beta Program Overview
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
 
Algolia @ProductTank Paris #13 - Dec 2014
Algolia @ProductTank Paris #13 - Dec 2014Algolia @ProductTank Paris #13 - Dec 2014
Algolia @ProductTank Paris #13 - Dec 2014
 
Efeito WOW!!!
Efeito WOW!!!Efeito WOW!!!
Efeito WOW!!!
 
Aiml
Aiml Aiml
Aiml
 
Top Secret: GCHQ: The Art of Deception. Training for a New Generation of On...
Top Secret:  GCHQ:  The Art of Deception. Training for a New Generation of On...Top Secret:  GCHQ:  The Art of Deception. Training for a New Generation of On...
Top Secret: GCHQ: The Art of Deception. Training for a New Generation of On...
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 

Similar to Dynamic Language Performance

Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicGieno Miao
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futuresnithinmohantk
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicTimothy Perrett
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Robotlegs on Top of Gaia
Robotlegs on Top of GaiaRobotlegs on Top of Gaia
Robotlegs on Top of GaiaJesse Warden
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Tomas Petricek
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)Shoaib Ghachi
 
HexRaysCodeXplorer: object oriented RE for fun and profit
HexRaysCodeXplorer: object oriented RE for fun and profitHexRaysCodeXplorer: object oriented RE for fun and profit
HexRaysCodeXplorer: object oriented RE for fun and profitAlex Matrosov
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And TricksJulie Lerman
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templatingbcruhl
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...apidays
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?Kevin Pilch
 

Similar to Dynamic Language Performance (20)

Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamic
 
Basic Hibernate Final
Basic Hibernate FinalBasic Hibernate Final
Basic Hibernate Final
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Robotlegs on Top of Gaia
Robotlegs on Top of GaiaRobotlegs on Top of Gaia
Robotlegs on Top of Gaia
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#Accessing loosely structured data from F# and C#
Accessing loosely structured data from F# and C#
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
HexRaysCodeXplorer: object oriented RE for fun and profit
HexRaysCodeXplorer: object oriented RE for fun and profitHexRaysCodeXplorer: object oriented RE for fun and profit
HexRaysCodeXplorer: object oriented RE for fun and profit
 
Javascript
JavascriptJavascript
Javascript
 
2.dynamic
2.dynamic2.dynamic
2.dynamic
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
 
Javascript Templating
Javascript TemplatingJavascript Templating
Javascript Templating
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Dynamic Language Performance

  • 1. Dynamic Language Performanceor How I Learned to Love Metaprogramming W. Kevin Hazzard, C# MVP NoVA Code Camp October 2009
  • 2. Agenda MetaObjects and MetaProgramming Dynamic Language Runtime Architecture The dynamic keyword in C# 4 The CallSite<T> Class The CSharpRuntimeBinder DynamicMetaObjects Adaptive Inline Caching Demonstrations Fluent XML Parsing Performance of Python to C# Integration
  • 3. Metaobject Visualization Metaobject control create invoke Backing Objects Users and programs interact with metaobjects, not directly with their backing objects.
  • 5. The dynamic Keyword [Dynamic] objectDX = someFunction(); dynamic DX = someFunction(); DX( ‘A’ ); DX.Foo( 1 ); DX.Bar = ‘X’; int V = DX.Baz; DX[0] = 100; string S = DX[0]; // invoke the object // invoke the Foo member // set the Bar member // convert the Baz member to integer // set index 0 to 100 // convert index 0 to string Is dynamic a new type? No The dynamic type is totally static  This type is a signal to the compiler to perform late binding
  • 6. Let's Stop and Reflect class Program{ dynamic Jabberwocky( dynamicarg ) { return arg.foo(); } } [return: Dynamic] object Jabberwocky( [Dynamic] objectarg ) { if (<Jabberwocky>o__SiteContainer2.<>p__Site3 == null) { <Jabberwocky>o__SiteContainer2.<>p__Site3 = CallSite<Func<CallSite, object, object>>.Create( newCSharpInvokeMemberBinder( CSharpCallFlags.None, "foo", typeof( Program ), null, newCSharpArgumentInfo[] { newCSharpArgumentInfo( CSharpArgumentInfoFlags.None, null ) } ) ); } return <Jabberwocky>o__SiteContainer2.<>p__Site3.Target( <Jabberwocky>o__SiteContainer2.<>p__Site3, arg ); }
  • 7. The CallSite<T> Class In the System.Runtime.CompilerServices namespace Created and managed in a static container class for each venue Key members: Create – creates and assign a binder Target – a delegate that invokes the binder Binder – connects an appropriate metaobject to the underlying call implementation
  • 8. The CSharpRuntimeBinder What might these describe? Semantic Checker Symbol Table Expression Tree Creator Expression Factory Context Info Controller Dispatcher
  • 9. What is a metaobject? An object that: May contain info on the: Creates Controls Invokes Describes Implements Interfaces of Type of Methods of Fields of Properties of Attributes of … another object
  • 10.
  • 11. All expression tree-orientedBindCreateInstance BindBinaryOperation BindUnaryOperation BindConvert BindDeleteMember BindDeleteIndex BindInvoke BindInvokeMember BindGetMember BindSetMember BindGetIndex BindSetIndex
  • 12. IDynamicMetaObjectProvider public interface IDynamicMetaObjectProvider { DynamicMetaObject GetMetaObject( Expression parameter ); } Pattern for implementing a custom metaobject The returned DynamicMetaObject must implement all twelve binding methods (and more) Lots of Expression Tree knowledge is required Not a trivial exercise
  • 13. DynamicObject to the rescue! public class DynamicObject : IDynamicMetaObjectProvider { protected DynamicObject(); public virtual DynamicMetaObjectGetMetaObject(...); public virtual boolTryBinaryOperation(...); public virtual boolTryConvert(...); public virtual boolTryCreateInstance(...); public virtual boolTryDeleteIndex(...); public virtual boolTryDeleteMember(...); public virtual boolTryGetIndex(...); public virtual boolTryGetMember(...); public virtual boolTryInvoke(...); public virtual boolTryInvokeMember(...); public virtual boolTrySetIndex(...); public virtual boolTrySetMember(...); public virtual boolTryUnaryOperation(...); }
  • 14. Example – Fluent XML Parsing Wouldn't it be nice if we could read and write XML like a set of nested objects without deep knowledge of the XML DOM or LINQ to XML? <books pubdate="2009-06-15"> <book price="45.99" title="Surgery for Dummies"> <id isbn10="4389880339"/> <authors> <author> <name> <first>Mortimer</first> <last>Snerdly</last> </name> <email address="mort@surgery.com"/> </author> </authors> </book> </books> WriteLine( books.book[0].authors.author[0].name.first);
  • 15. Fluent XML pARSING in C# Demonstration
  • 16. Adaptive Inline Caching Each CallSite uses 3 levels of caching Level 0 – a dynamically generated delegate for some of the call patterns encountered at the site Level 1 – a read-only set of rules for all of the call patterns that the site has seen so far Level 2 – a read-only set of rules that spans multiple call sites
  • 17. What about level 2 cache misses? A level 2 cache miss causes: The creation of a new rule The insertion of the new rule into the level 2 cache (on the ActionBinder) The insertion of the new rule into the level 1 cache (on the CallSite rule set) Possible insertion into the level 0 cache (on the CallSite dynamic delegate)
  • 18. Performance ofPython to C# Integration Demonstration
  • 19. For More Information www.gotnet.biz/Blog www.voidspace.org.uk blogs.msdn.com/samng blogs.msdn.com/curth blogs.msdn.com/cburrows blogs.msdn.com/mmaly