SlideShare une entreprise Scribd logo
1  sur  13
Post-compilation
optimization in .net
IL weaving for C# programmers
Hubert Taler / BLSTream
Agenda
• .net Compilation Process
• Intermediate language and what can we do with it
• What can we do with it?
• Aspect Oriented Programming
• … and why we shouldn’t
• Fody
• Code samples
.NET compilation process
Source code
Translation
to IL
Compiling to
native code
and running
Intermediate Language
• Firstly known as MSIL, later renamed to CIL
• Platform independent instructions
• Enriched with metadata
• Very similar to assembly languages
• Can be translated into assembly
• By JIT (Just in time) compiler
• By ngen.exe to build native image
• By building universal app
IL example
What can we do with IL?
• Usually – nothing
• Really – we shouldn’t
• Reflection.Emit
• Precompiled, instead of reflection (ie type descriptors)
• Dynamic proxies
• Mocks (moq)
• Poor man’s AOP, patterns design
• Postsharp $$$
• Enriching code without making mess
• Fody (free!)
Theory: Aspect Oriented Programming
• Created for better concerns separation
• Based on advices
• Always log the call when method name begins with „Set”
• Always check for login token when the service is called
• Allows less cluttered code
• Commonly implemented by weaving
• Pre-compilation weaving (C++ preprocesor)
• Post-compilation weaving (C# IL, Java bytecode)
Typical AOP proces (advice)
BeforeAdvice
Always call me
before Method()
Method()
AfterAdvice
Always call me
after Method()
Normal
control
flow
Normal
control
flow
Typical uses of IL Weaving / AOP
• INotifyPropertyChanged
• Logging
• Null-checking
• Permissions-checking
• Undo-redo pattern
• Freeze pattern
• Method call cache
• Global handling of exceptions
• Encrypting string literals
• … and many more
The criticism of AOP
• Losing control of „what-where” (obscuring control flow)
• Error propagation
• Programmers afraid
• Crosscutting means no one can be an expert in part of code
• AOP is patented!
Meal of the day: Fody
• Free and open source
• Plugin architecture
• No artifacts in your output
• No references
• No installs
• Works in MSBuild
• Doesn’t break your compilation (signing, strong name)
• „Install-Package Fody”
Time to see something!
Thank you
• Hubert Taler
• hubert.taler@blstream.com

Contenu connexe

En vedette

Wprowadzenie do CoreBluetooth
Wprowadzenie do CoreBluetoothWprowadzenie do CoreBluetooth
Wprowadzenie do CoreBluetoothintive
 
Fisiologia y sexualidad 3era tarea
Fisiologia y sexualidad  3era tareaFisiologia y sexualidad  3era tarea
Fisiologia y sexualidad 3era tareayoicegb
 
Isu isu keperihatinan negara
Isu isu keperihatinan negaraIsu isu keperihatinan negara
Isu isu keperihatinan negaradka1d
 
pengajian malaysia
pengajian malaysiapengajian malaysia
pengajian malaysiadka1d
 
Pengajian malaysia
Pengajian malaysiaPengajian malaysia
Pengajian malaysiadka1d
 

En vedette (8)

Wprowadzenie do CoreBluetooth
Wprowadzenie do CoreBluetoothWprowadzenie do CoreBluetooth
Wprowadzenie do CoreBluetooth
 
Fecundacion desarrollo embrionario y fetal
Fecundacion desarrollo embrionario y fetalFecundacion desarrollo embrionario y fetal
Fecundacion desarrollo embrionario y fetal
 
Fisiologia y sexualidad 3era tarea
Fisiologia y sexualidad  3era tareaFisiologia y sexualidad  3era tarea
Fisiologia y sexualidad 3era tarea
 
Ira final
Ira finalIra final
Ira final
 
DESARROLLO COGNOSCITIVO Y EL LENGUAJE EN LA PRIMERA INFANCIA
DESARROLLO COGNOSCITIVO Y EL LENGUAJE EN LA PRIMERA INFANCIADESARROLLO COGNOSCITIVO Y EL LENGUAJE EN LA PRIMERA INFANCIA
DESARROLLO COGNOSCITIVO Y EL LENGUAJE EN LA PRIMERA INFANCIA
 
Isu isu keperihatinan negara
Isu isu keperihatinan negaraIsu isu keperihatinan negara
Isu isu keperihatinan negara
 
pengajian malaysia
pengajian malaysiapengajian malaysia
pengajian malaysia
 
Pengajian malaysia
Pengajian malaysiaPengajian malaysia
Pengajian malaysia
 

Plus de intive

Rok z Android MVVM
Rok z Android MVVMRok z Android MVVM
Rok z Android MVVMintive
 
Don't Forget About the Layout
Don't Forget About the LayoutDon't Forget About the Layout
Don't Forget About the Layoutintive
 
You Don't Need Dependency Injection
You Don't Need Dependency InjectionYou Don't Need Dependency Injection
You Don't Need Dependency Injectionintive
 
OWASP Open SAMM
OWASP Open SAMMOWASP Open SAMM
OWASP Open SAMMintive
 
Porównanie architektur MVVM i MVC (iOS)
Porównanie architektur MVVM i MVC (iOS)Porównanie architektur MVVM i MVC (iOS)
Porównanie architektur MVVM i MVC (iOS)intive
 
.Net anywhere
.Net anywhere.Net anywhere
.Net anywhereintive
 
Front end - advanced development for beginners
Front end - advanced development for beginnersFront end - advanced development for beginners
Front end - advanced development for beginnersintive
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and testsintive
 
Patronage 2016 Windows 10 Warsztaty
Patronage 2016 Windows 10 WarsztatyPatronage 2016 Windows 10 Warsztaty
Patronage 2016 Windows 10 Warsztatyintive
 
Techniczna organizacja zespołu cz 2
Techniczna organizacja zespołu cz 2Techniczna organizacja zespołu cz 2
Techniczna organizacja zespołu cz 2intive
 
Techniczna organizacja zespołu
Techniczna organizacja zespołuTechniczna organizacja zespołu
Techniczna organizacja zespołuintive
 
Organizacja zespołu
Organizacja zespołuOrganizacja zespołu
Organizacja zespołuintive
 
Nie tylko C# - Ekosystem Microsoft dla programistów
Nie tylko C# - Ekosystem Microsoft dla programistówNie tylko C# - Ekosystem Microsoft dla programistów
Nie tylko C# - Ekosystem Microsoft dla programistówintive
 
[PL] MVP do MVVM - separacja warstw w aplikacji androidowej
[PL] MVP do MVVM - separacja warstw w aplikacji androidowej[PL] MVP do MVVM - separacja warstw w aplikacji androidowej
[PL] MVP do MVVM - separacja warstw w aplikacji androidowejintive
 
Tips & Tricks Android
Tips & Tricks AndroidTips & Tricks Android
Tips & Tricks Androidintive
 
Apple Watch - Getting Started
Apple Watch - Getting StartedApple Watch - Getting Started
Apple Watch - Getting Startedintive
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
CoreLocation (iOS) in details
CoreLocation (iOS) in detailsCoreLocation (iOS) in details
CoreLocation (iOS) in detailsintive
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practiceintive
 
Java Script - Object-Oriented Programming
Java Script - Object-Oriented ProgrammingJava Script - Object-Oriented Programming
Java Script - Object-Oriented Programmingintive
 

Plus de intive (20)

Rok z Android MVVM
Rok z Android MVVMRok z Android MVVM
Rok z Android MVVM
 
Don't Forget About the Layout
Don't Forget About the LayoutDon't Forget About the Layout
Don't Forget About the Layout
 
You Don't Need Dependency Injection
You Don't Need Dependency InjectionYou Don't Need Dependency Injection
You Don't Need Dependency Injection
 
OWASP Open SAMM
OWASP Open SAMMOWASP Open SAMM
OWASP Open SAMM
 
Porównanie architektur MVVM i MVC (iOS)
Porównanie architektur MVVM i MVC (iOS)Porównanie architektur MVVM i MVC (iOS)
Porównanie architektur MVVM i MVC (iOS)
 
.Net anywhere
.Net anywhere.Net anywhere
.Net anywhere
 
Front end - advanced development for beginners
Front end - advanced development for beginnersFront end - advanced development for beginners
Front end - advanced development for beginners
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
Patronage 2016 Windows 10 Warsztaty
Patronage 2016 Windows 10 WarsztatyPatronage 2016 Windows 10 Warsztaty
Patronage 2016 Windows 10 Warsztaty
 
Techniczna organizacja zespołu cz 2
Techniczna organizacja zespołu cz 2Techniczna organizacja zespołu cz 2
Techniczna organizacja zespołu cz 2
 
Techniczna organizacja zespołu
Techniczna organizacja zespołuTechniczna organizacja zespołu
Techniczna organizacja zespołu
 
Organizacja zespołu
Organizacja zespołuOrganizacja zespołu
Organizacja zespołu
 
Nie tylko C# - Ekosystem Microsoft dla programistów
Nie tylko C# - Ekosystem Microsoft dla programistówNie tylko C# - Ekosystem Microsoft dla programistów
Nie tylko C# - Ekosystem Microsoft dla programistów
 
[PL] MVP do MVVM - separacja warstw w aplikacji androidowej
[PL] MVP do MVVM - separacja warstw w aplikacji androidowej[PL] MVP do MVVM - separacja warstw w aplikacji androidowej
[PL] MVP do MVVM - separacja warstw w aplikacji androidowej
 
Tips & Tricks Android
Tips & Tricks AndroidTips & Tricks Android
Tips & Tricks Android
 
Apple Watch - Getting Started
Apple Watch - Getting StartedApple Watch - Getting Started
Apple Watch - Getting Started
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
CoreLocation (iOS) in details
CoreLocation (iOS) in detailsCoreLocation (iOS) in details
CoreLocation (iOS) in details
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
Java Script - Object-Oriented Programming
Java Script - Object-Oriented ProgrammingJava Script - Object-Oriented Programming
Java Script - Object-Oriented Programming
 

Dernier

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 

Dernier (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 

Post-compilation optimization in .NET

  • 1. Post-compilation optimization in .net IL weaving for C# programmers Hubert Taler / BLSTream
  • 2. Agenda • .net Compilation Process • Intermediate language and what can we do with it • What can we do with it? • Aspect Oriented Programming • … and why we shouldn’t • Fody • Code samples
  • 3. .NET compilation process Source code Translation to IL Compiling to native code and running
  • 4. Intermediate Language • Firstly known as MSIL, later renamed to CIL • Platform independent instructions • Enriched with metadata • Very similar to assembly languages • Can be translated into assembly • By JIT (Just in time) compiler • By ngen.exe to build native image • By building universal app
  • 6. What can we do with IL? • Usually – nothing • Really – we shouldn’t • Reflection.Emit • Precompiled, instead of reflection (ie type descriptors) • Dynamic proxies • Mocks (moq) • Poor man’s AOP, patterns design • Postsharp $$$ • Enriching code without making mess • Fody (free!)
  • 7. Theory: Aspect Oriented Programming • Created for better concerns separation • Based on advices • Always log the call when method name begins with „Set” • Always check for login token when the service is called • Allows less cluttered code • Commonly implemented by weaving • Pre-compilation weaving (C++ preprocesor) • Post-compilation weaving (C# IL, Java bytecode)
  • 8. Typical AOP proces (advice) BeforeAdvice Always call me before Method() Method() AfterAdvice Always call me after Method() Normal control flow Normal control flow
  • 9. Typical uses of IL Weaving / AOP • INotifyPropertyChanged • Logging • Null-checking • Permissions-checking • Undo-redo pattern • Freeze pattern • Method call cache • Global handling of exceptions • Encrypting string literals • … and many more
  • 10. The criticism of AOP • Losing control of „what-where” (obscuring control flow) • Error propagation • Programmers afraid • Crosscutting means no one can be an expert in part of code • AOP is patented!
  • 11. Meal of the day: Fody • Free and open source • Plugin architecture • No artifacts in your output • No references • No installs • Works in MSBuild • Doesn’t break your compilation (signing, strong name) • „Install-Package Fody”
  • 12. Time to see something!
  • 13. Thank you • Hubert Taler • hubert.taler@blstream.com