SlideShare a Scribd company logo
Instrumentation &
the Pitfalls of
Abstraction
ESUG - 2023 - Lyon
* Supported by AlaMVic Action Exploratoire INRIA
guillermo.polito@inria.fr
@guillep
Evref
fervE
1
Generated by DALL-E
First: About Me
2
Evref
fervE
• Keywords: compilers, testing, test generation
• Ph.D.: Re
fl
ection, debloating, dynamic updates
• Interests: tooling, benchmarking, 日本語, board games, concurrency
Talk to me!
Or: guillermo.polito@inria.fr
guillermo.polito@inria.fr
@guillep
Building Dynamic Analyses
• Dynamic call graphs
• Code coverage
• Pro
fi
lers
• Time
• Number of calls
3
Method Wrappers, Objects as Methods
4
Remember Method Lookup
sender receiver
class
s1
s2
…
s4
…
m1
m2
m3
s2
superclass
s1 …
s5 …
inherits from
instance of
reference
message
5
sender receiver
class
s1
s2
…
s4
…
m1
m3
s2
superclass
s1 …
s5 …
Objects as methods
o1
inherits from
instance of
reference
message
6
sender receiver
class
s1
s2
…
s4
…
m1
m3
s2
superclass
s1 …
s5 …
Objects as methods + run:with:in:
o1
run:with:in:
inherits from
instance of
reference
message
7
How far can we get with
run:with:in: ?
8
A First Method Proxy
run: aSelector with: anArrayOfObjects in: aReceiver
| result |
self logBefore: aSelector.
result := self
forwardMethod: originalMethod
withReceiver: aReceiver
withArguments: anArrayOfObjects.
self logAfter: aSelector.
^ result
9
Let’s instrument factorial
doit 17
px
log:
fwd…
factorial
run:with:in:
10
doit 17
Let’s instrument factorial
px
log:
fwd…
run:with:in:
factorial
11
Let’s instrument factorial
doit 17
px
log:
fwd…
run:with:in:
factorial
16
factorial
…
12
Let’s instrument factorial
doit 17
px
log:
fwd…
run:with:in:
factorial
16
px
log:
fwd…
run:with:in:
factorial
…
13
Let’s get a bit more hardcore
14
doit
aSet
add:
px
run:with:in: log:
Instrumenting Set>>#add:
15
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
Instrumenting Set>>#add:
16
Instrumenting Set>>#add:
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
run:with:in:
17
Meta-Recursions
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
run:with:in:
• The instrumentation gets instrumented!
• And, with more complex
instrumentation, more di
ffi
cult to debug
• The burden: on the developer
18
Solving Meta-Recursions
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
19
Solving Meta-Recursions
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
Instrumentation zone
20
Solving Meta-Recursions
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
Instrumentation zone
21
And That’s not All
• Stack unwind (non-local returns, exceptions) pass around the logAfter:
• Concurrent access to our instrumentation zone?
• lose logs
• break the instrumentation
• Maybe we can do some concessions: e.g., do not proxy the proxy…
This burden, is on the developer
22
The Cost of Missing Abstraction
• The language gives us only low-level instrumentation hooks
• #run:with:in:
• #doesNotUnderstand:
• #cannotInterpret:
• i.e., they are at the wrong level of abstraction for proper instrumentation
Covering the GAP, is on the developer
23
The Proxy We Have
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
Instrumentation zone
24
The Stratified Proxy We Want
doit
aSet
add:
px
run:with:in: log:
otherSet
add:
Instrumentation zone
handler
before:
after:
Infrastructure
• Meta-recursion
• Concurrency
User concern
• logging?
• analysis?
25
Stratified Proxies
26
Safe Method Proxies + Exact Method Profiler
• Method Proxies: https://github.com/pharo-contributions/MethodProxies
• Method Pro
fi
ler: https://github.com/pharo-contributions/MethodPro
fi
ler
• + common instrumentation layer between proxies and meta-links !
27
Let’s get a bit more hardcore
again
28
Let’s Instrument the Compiler
prf := PrfMethodProfiler new.
prf addPackage: OpalCompiler package.
prf addPackage: RBParser package.
prf profile: [ Integer recompile ].
29
prf := PrfMethodProfiler new.
^ self < 2
ifTrue: [1]
ifFalse: [
(self-1) benchFib + (self-2) benchFib + 1]
Let’s Benchmark with Fibonacci
• Best case for proxy infrastructure
• no exceptions
• no non-local return
• no meta-recursion
• no concurrent usages by default
fi
b n - 1
fi
b n - 2
fi
b n - 3
fi
b n - 4
fi
b n - 4
fi
b n - 5
fi
b n - 3
fi
b n - 4
fi
b n - 5
Let’s Benchmark with Fibonacci (II)
• Good case to measure pro
fi
ler/proxy overhead
• Simulate a big call-tree
• Leaves are fast paths (early exits)
• => high overhead expected
• fib(n) ~~ number of messages
fi
b n - 1
fi
b n - 2
fi
b n - 3
fi
b n - 4
fi
b n - 4
fi
b n - 5
fi
b n - 3
fi
b n - 4
fi
b n - 5
Our Lower Bound is run:with:in:
35
run: aSelector with: anArrayOfObjects in: aReceiver
^ self
forwardMethod: originalMethod
withReceiver: aReceiver
withArguments: anArrayOfObjects
run:with:in: Performance vs fib(x)
• ~25x slower !
• Seems faster for lower args
• Noise due to µs measures?
36
0 10 20 30
0
5
10
15
20
25
Time
(relative
to
no
proxy)
Fibonacci Argument
* Averages of 100 runs in µs. X = 1 to: 28
run:with:in: Performance vs Messages
• Consistent ~25x overhead
• Cries for language
implementation
improvement (!!)
37 * Averages of 100 runs in µs.
0 300000 600000 900000 1200000
0
5
10
15
20
25
Time
(relative
to
no
proxy)
Messages
The Cost of Safety
• Safe method proxies are ~3000x worse
• Non-clean closures
• allocation
• thisContext rei
fi
cation
• More messages (!)
• #ensure:
• meta-recursion control
• #before, #after hooks
38
0 300000 600000 900000 1200000
0
1000
2000
3000
4000
Time
(relative
to
no
proxy)
Messages
* Averages of 100 runs in µs.
Can we get better?
• Down to ~400x just removing abstraction
• Inlinings (!!)
• to remove messages
• to avoid blocks
• di
ff
erentiate fast vs slow path
• concurrent, meta-recursive
39
0 300000 600000 900000 1200000
0
500
1000
1500
2000
2500
3000
3500
Time
(relative
to
no
proxy)
Messages
* Averages of 100 runs in µs.
Overhead of Call-Tree Construction
• 2 proxy variants
• Generic: handler object
• Customized: inlined handler
• 2 instrumentation variants
• Online: build the call tree while executing
• Delayed: trace the minimum to build it in a post-process
• Comparison Baseline: safe+opt proxy with no instrumentation
40 * Averages of 100 runs in µs.
Call-tree construction
• Generic + Online was o
ff
the charts :)
• => o
ff
the presentation too
• Delaying the analysis is the best
• Customization gets only slightly better
• removes 4 messages per call
41 * Averages of 100 runs in µs.
0 300000 600000 900000 1200000
0
2
4
6
8
10
12
Time
(relative
to
Generic
Online
Analysis)
Messages
Generic - No Instrumentation
Customized Proxy - Online Analysis
Generic Proxy - Delayed Analysis
Customized Proxy - Delayed Analysis
Call-tree construction
• Generic + Online was o
ff
the charts :)
• => o
ff
the presentation too
• Delaying the analysis is the best
• Customization gets only slightly better
• removes 4 messages per call
42 * Averages of 100 runs in µs.
0 300000 600000 900000 1200000
0
2
4
6
8
10
12
Time
(relative
to
Generic
Online
Analysis)
Messages
Generic - No Instrumentation
Customized Proxy - Online Analysis
Generic Proxy - Delayed Analysis
Customized Proxy - Delayed Analysis
Zooming in
• Delayed is ~1.25x proxy alone
~1.25 * 400x (safety) ~= ~500x overhead
(over no instrumentation)
43 * Averages of 100 runs in µs.
0 300000 600000 900000 1200000
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
Time
(relative
to
Generic
Online
Analysis) Messages
Generic - No Instrumentation
Generic Proxy - Delayed Analysis
Customized Proxy - Delayed Analysis
Profiling the Compiler — again
• Partial Instrumentation
• Down from ~110x to ~12x
44
Baseline
Generic+Online
Customized+Delayed
0.0
20.0
40.0
60.0
80.0
100.0
120.0
140.0
Time
(relative
to
no
instrumentation)
prf := PrfMethodProfiler new.
prf addPackage: OpalCompiler package.
prf addPackage: RBParser package.
prf profile: [ Integer recompile ].
Takeaways
• Users need native language support for instrumentation
• Safe, strati
fi
ed and **e
ffi
cient**
• Low-level hooks are not enough: they miss abstractions
• Think twice when writing your own proxy implementation!
• Think concurrency, think stack unwind, thing meta-recursions
45 * Supported by AlaMVic Action Exploratoire INRIA
Evref
fervE
https://github.com/pharo-contributions/MethodProxies
https://github.com/pharo-contributions/MethodPro
fi
ler

More Related Content

Similar to Instrumentation & the Pitfalls of Abstraction

running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on android
Koan-Sin Tan
 
ACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
ACSAC2016: Code Obfuscation Against Symbolic Execution AttacksACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
ACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
Sebastian Banescu
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...
SignalFx
 
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...Silvio Cesare
 
NLP Classifier Models & Metrics
NLP Classifier Models & MetricsNLP Classifier Models & Metrics
NLP Classifier Models & Metrics
Sanghamitra Deb
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
baran19901990
 
Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)
Peter Breuer
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
Brendan Gregg
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
Fwdays
 
Deep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesDeep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesTuri, Inc.
 
Serial-War
Serial-WarSerial-War
Serial-War
Xuechao Wu
 
Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...
Lucas Leong
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
Wei-Bo Chen
 
High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
Work-Bench
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
ESUG
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
PYCON MY PLT
 
Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leeds
Damien Seguy
 
Performance analysis and troubleshooting using DTrace
Performance analysis and troubleshooting using DTracePerformance analysis and troubleshooting using DTrace
Performance analysis and troubleshooting using DTrace
Graeme Jenkinson
 
Approximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming ApplicationsApproximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming Applications
Debasish Ghosh
 

Similar to Instrumentation & the Pitfalls of Abstraction (20)

running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on android
 
ACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
ACSAC2016: Code Obfuscation Against Symbolic Execution AttacksACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
ACSAC2016: Code Obfuscation Against Symbolic Execution Attacks
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...
 
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
FooCodeChu - Services for Software Analysis, Malware Detection, and Vulnerabi...
 
NLP Classifier Models & Metrics
NLP Classifier Models & MetricsNLP Classifier Models & Metrics
NLP Classifier Models & Metrics
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)Open Source Verification under a Cloud (OpenCert 2010)
Open Source Verification under a Cloud (OpenCert 2010)
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
Deep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep FeaturesDeep Learning Made Easy with Deep Features
Deep Learning Made Easy with Deep Features
 
Serial-War
Serial-WarSerial-War
Serial-War
 
Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...Make static instrumentation great again, High performance fuzzing for Windows...
Make static instrumentation great again, High performance fuzzing for Windows...
 
Nyt Prof 200910
Nyt Prof 200910Nyt Prof 200910
Nyt Prof 200910
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
 
High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Python testing like a pro by Keith Yang
Python testing like a pro by Keith YangPython testing like a pro by Keith Yang
Python testing like a pro by Keith Yang
 
Strong typing @ php leeds
Strong typing  @ php leedsStrong typing  @ php leeds
Strong typing @ php leeds
 
Performance analysis and troubleshooting using DTrace
Performance analysis and troubleshooting using DTracePerformance analysis and troubleshooting using DTrace
Performance analysis and troubleshooting using DTrace
 
Approximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming ApplicationsApproximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming Applications
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
ESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
ESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
ESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
ESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
ESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
ESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
ESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
ESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
ESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
ESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
ESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
ESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 

Recently uploaded (20)

Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 

Instrumentation & the Pitfalls of Abstraction

  • 1. Instrumentation & the Pitfalls of Abstraction ESUG - 2023 - Lyon * Supported by AlaMVic Action Exploratoire INRIA guillermo.polito@inria.fr @guillep Evref fervE 1 Generated by DALL-E
  • 2. First: About Me 2 Evref fervE • Keywords: compilers, testing, test generation • Ph.D.: Re fl ection, debloating, dynamic updates • Interests: tooling, benchmarking, 日本語, board games, concurrency Talk to me! Or: guillermo.polito@inria.fr guillermo.polito@inria.fr @guillep
  • 3. Building Dynamic Analyses • Dynamic call graphs • Code coverage • Pro fi lers • Time • Number of calls 3
  • 5. Remember Method Lookup sender receiver class s1 s2 … s4 … m1 m2 m3 s2 superclass s1 … s5 … inherits from instance of reference message 5
  • 6. sender receiver class s1 s2 … s4 … m1 m3 s2 superclass s1 … s5 … Objects as methods o1 inherits from instance of reference message 6
  • 7. sender receiver class s1 s2 … s4 … m1 m3 s2 superclass s1 … s5 … Objects as methods + run:with:in: o1 run:with:in: inherits from instance of reference message 7
  • 8. How far can we get with run:with:in: ? 8
  • 9. A First Method Proxy run: aSelector with: anArrayOfObjects in: aReceiver | result | self logBefore: aSelector. result := self forwardMethod: originalMethod withReceiver: aReceiver withArguments: anArrayOfObjects. self logAfter: aSelector. ^ result 9
  • 10. Let’s instrument factorial doit 17 px log: fwd… factorial run:with:in: 10
  • 11. doit 17 Let’s instrument factorial px log: fwd… run:with:in: factorial 11
  • 12. Let’s instrument factorial doit 17 px log: fwd… run:with:in: factorial 16 factorial … 12
  • 13. Let’s instrument factorial doit 17 px log: fwd… run:with:in: factorial 16 px log: fwd… run:with:in: factorial … 13
  • 14. Let’s get a bit more hardcore 14
  • 18. Meta-Recursions doit aSet add: px run:with:in: log: otherSet add: run:with:in: • The instrumentation gets instrumented! • And, with more complex instrumentation, more di ffi cult to debug • The burden: on the developer 18
  • 22. And That’s not All • Stack unwind (non-local returns, exceptions) pass around the logAfter: • Concurrent access to our instrumentation zone? • lose logs • break the instrumentation • Maybe we can do some concessions: e.g., do not proxy the proxy… This burden, is on the developer 22
  • 23. The Cost of Missing Abstraction • The language gives us only low-level instrumentation hooks • #run:with:in: • #doesNotUnderstand: • #cannotInterpret: • i.e., they are at the wrong level of abstraction for proper instrumentation Covering the GAP, is on the developer 23
  • 24. The Proxy We Have doit aSet add: px run:with:in: log: otherSet add: Instrumentation zone 24
  • 25. The Stratified Proxy We Want doit aSet add: px run:with:in: log: otherSet add: Instrumentation zone handler before: after: Infrastructure • Meta-recursion • Concurrency User concern • logging? • analysis? 25
  • 27. Safe Method Proxies + Exact Method Profiler • Method Proxies: https://github.com/pharo-contributions/MethodProxies • Method Pro fi ler: https://github.com/pharo-contributions/MethodPro fi ler • + common instrumentation layer between proxies and meta-links ! 27
  • 28. Let’s get a bit more hardcore again 28
  • 29. Let’s Instrument the Compiler prf := PrfMethodProfiler new. prf addPackage: OpalCompiler package. prf addPackage: RBParser package. prf profile: [ Integer recompile ]. 29
  • 31.
  • 32. ^ self < 2 ifTrue: [1] ifFalse: [ (self-1) benchFib + (self-2) benchFib + 1]
  • 33. Let’s Benchmark with Fibonacci • Best case for proxy infrastructure • no exceptions • no non-local return • no meta-recursion • no concurrent usages by default fi b n - 1 fi b n - 2 fi b n - 3 fi b n - 4 fi b n - 4 fi b n - 5 fi b n - 3 fi b n - 4 fi b n - 5
  • 34. Let’s Benchmark with Fibonacci (II) • Good case to measure pro fi ler/proxy overhead • Simulate a big call-tree • Leaves are fast paths (early exits) • => high overhead expected • fib(n) ~~ number of messages fi b n - 1 fi b n - 2 fi b n - 3 fi b n - 4 fi b n - 4 fi b n - 5 fi b n - 3 fi b n - 4 fi b n - 5
  • 35. Our Lower Bound is run:with:in: 35 run: aSelector with: anArrayOfObjects in: aReceiver ^ self forwardMethod: originalMethod withReceiver: aReceiver withArguments: anArrayOfObjects
  • 36. run:with:in: Performance vs fib(x) • ~25x slower ! • Seems faster for lower args • Noise due to µs measures? 36 0 10 20 30 0 5 10 15 20 25 Time (relative to no proxy) Fibonacci Argument * Averages of 100 runs in µs. X = 1 to: 28
  • 37. run:with:in: Performance vs Messages • Consistent ~25x overhead • Cries for language implementation improvement (!!) 37 * Averages of 100 runs in µs. 0 300000 600000 900000 1200000 0 5 10 15 20 25 Time (relative to no proxy) Messages
  • 38. The Cost of Safety • Safe method proxies are ~3000x worse • Non-clean closures • allocation • thisContext rei fi cation • More messages (!) • #ensure: • meta-recursion control • #before, #after hooks 38 0 300000 600000 900000 1200000 0 1000 2000 3000 4000 Time (relative to no proxy) Messages * Averages of 100 runs in µs.
  • 39. Can we get better? • Down to ~400x just removing abstraction • Inlinings (!!) • to remove messages • to avoid blocks • di ff erentiate fast vs slow path • concurrent, meta-recursive 39 0 300000 600000 900000 1200000 0 500 1000 1500 2000 2500 3000 3500 Time (relative to no proxy) Messages * Averages of 100 runs in µs.
  • 40. Overhead of Call-Tree Construction • 2 proxy variants • Generic: handler object • Customized: inlined handler • 2 instrumentation variants • Online: build the call tree while executing • Delayed: trace the minimum to build it in a post-process • Comparison Baseline: safe+opt proxy with no instrumentation 40 * Averages of 100 runs in µs.
  • 41. Call-tree construction • Generic + Online was o ff the charts :) • => o ff the presentation too • Delaying the analysis is the best • Customization gets only slightly better • removes 4 messages per call 41 * Averages of 100 runs in µs. 0 300000 600000 900000 1200000 0 2 4 6 8 10 12 Time (relative to Generic Online Analysis) Messages Generic - No Instrumentation Customized Proxy - Online Analysis Generic Proxy - Delayed Analysis Customized Proxy - Delayed Analysis
  • 42. Call-tree construction • Generic + Online was o ff the charts :) • => o ff the presentation too • Delaying the analysis is the best • Customization gets only slightly better • removes 4 messages per call 42 * Averages of 100 runs in µs. 0 300000 600000 900000 1200000 0 2 4 6 8 10 12 Time (relative to Generic Online Analysis) Messages Generic - No Instrumentation Customized Proxy - Online Analysis Generic Proxy - Delayed Analysis Customized Proxy - Delayed Analysis
  • 43. Zooming in • Delayed is ~1.25x proxy alone ~1.25 * 400x (safety) ~= ~500x overhead (over no instrumentation) 43 * Averages of 100 runs in µs. 0 300000 600000 900000 1200000 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 Time (relative to Generic Online Analysis) Messages Generic - No Instrumentation Generic Proxy - Delayed Analysis Customized Proxy - Delayed Analysis
  • 44. Profiling the Compiler — again • Partial Instrumentation • Down from ~110x to ~12x 44 Baseline Generic+Online Customized+Delayed 0.0 20.0 40.0 60.0 80.0 100.0 120.0 140.0 Time (relative to no instrumentation) prf := PrfMethodProfiler new. prf addPackage: OpalCompiler package. prf addPackage: RBParser package. prf profile: [ Integer recompile ].
  • 45. Takeaways • Users need native language support for instrumentation • Safe, strati fi ed and **e ffi cient** • Low-level hooks are not enough: they miss abstractions • Think twice when writing your own proxy implementation! • Think concurrency, think stack unwind, thing meta-recursions 45 * Supported by AlaMVic Action Exploratoire INRIA Evref fervE https://github.com/pharo-contributions/MethodProxies https://github.com/pharo-contributions/MethodPro fi ler