SlideShare una empresa de Scribd logo
1 de 17
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Blocks and Optimization
in VW
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
[ :x :y | |tmp| ...]
value
value:
value: value:
value: value: value:
valueWithArguments:
•InVisualWorks there are four types of blocks:
• Full Blocks
• Copying Blocks
• Clean Blocks
• Inlined Blocks
•The programmer does not have to explicitly mention.
•Inferred by the compiler. However, knowing the subtle
differences allows the programmer to write more efficient
code.
Blocks and Optimization inVW
S.Ducasse 4
• Read and assign temporary variables.
• Block containing explicit return ^.
• Compiled in a BlockClosure.
• Evaluation by the creation of an explicit
MethodContext or BlockContext object instead of
using a pseudo-object contained in the stack.
• Most costly
• Instead of:
• m1: arg1 m1: arg1
• arg1 isNil ^ arg1 isNil
• ifTrue: [^ 1] ifTrue: [1]
• ifTrue: [^ 2] ifTrue: [2]
Full Blocks
S.Ducasse 5
• Read temporary variables but do not assign them.
• No explicit return.
• Access instance variables of self and assign them.
• Not compiled into a BlockClosure.
• They are compiled by copying every access into the
block, thus avoiding explicit references to a context
where the copied variables appear.
• Their arguments and temporaries are merged into the
enclosing method’s context as “compiler-generated
temporaries”.
Copying Blocks
S.Ducasse 6
• Contain only reference block temporary variables or
global variables.
• No reference to self or to instance variables.
• nodes do: [:each | each name = #stef]
• nodes select: [:each | each isLocal]
Clean Blocks
S.Ducasse 7
• Code of certain methods, like whileFalse: ifTrue:, is
directly inlined into the code of the calling method.
• The literal blocks (without arguments) passed as
argument to such methods are also inlined in the
byte-code of the calling method.
• Inlined methods are whileTrue, whileTrue:, whileFalse,
whileFalse:, and: or:, ifTrue:, ifFalse:, ifTrue:ifFalse:,
ifFalse:ifTrue:, to:do:, to:do:by:
• Look in MessageNode>>transform* methods to see
the inlining
Inlined Blocks
S.Ducasse 8
• testInLined
• 1 to: 5 do: [:x| ]
• Compiled into :
• | t1 |
• t1 := 1.
• [t1 <= 5] whileTrue: [t1 := t1 + 1].
• But no BlockClosure is created (look into the byte
codes)
Inlined Blocks
S.Ducasse 9
• Instead of:
• |t|
• [:x | t := x foo] value: 1.
• t := t * 2.
• ^t
• The reference to t inside the block makes it at least a
copying block.
• t := makes it full.
• With the following we have a clean block.
• |t|
• t := [:x | x foo] value:1.
• t := t * 2.
• ^t
From Full to Copy
S.Ducasse 10
• Full blocks are evaluated in a separate context.
• The following code evaluates to false:
• |outerContext answer|
• outerContext := thisContext.
• (1 to: 1) do: [:i | answer := thisContext ==
outerContext].
• ^answer
• But the following evaluates to true because: to:do: is an
inlined block
• |outerContext answer|
• outerContext := thisContext.
• 1 to: 1 do: [:i | answer := thisContext == outerContext].
• ^answer
Contexts
S.Ducasse 11
• Instead of:
• |maxNumber|
• maxNumber := 0.
• #(1 2 43 56 2 49 3 2 0 ) do: [:each| maxNumber :=
each max: maxNumber].
• ^maxNumber
• Write
• #(1 2 43 56 2 49 3 2 0 ) inject: 0 into: [:maxNumber
:ele| maxNumber max: ele]
• no need for a temporary variable
• full block becomes a clean block
inject:into:
S.Ducasse 12
• str1 , str2 creates a new structure in which str1 and
str2 elements are stored
SequenceableCollection>>, aSequenceableCollection
"Answer a copy of the receiver concatenated with the argument,
a SequenceableCollection."
^self copyReplaceFrom: self size + 1
to: self size
with: aSequenceableCollection
SequenceableCollection>>copyReplaceFrom: start to: stop with:
replacementCollection
"Answer a copy of the receiver satisfying the following conditions:
.."
About String Concatenation
S.Ducasse 13
• Suppose that we want to concatenate a pretty long list
of strings, for example the keys of the Smalltalk
dictionary.
• |bigString|
• bigString := String new.
• Smalltalk keys do: [:aString | bigString := bigString, aString].
• Here the assignment of bigString leads to a Full Block
• We can suppress the assignment like that and thus
obtain a clean block
• |aStream|
• aStream:= WriteStream on: String new.
• Smalltalk keys do: [:aString | aStream nextPutAll: aString].
Streams, Blocks, and Optimization
S.Ducasse 14
• inject:into: allows us to suppress the reference to
variables that are outside the block and to obtain a
clean block.
• |aStream|
• aStream:= WriteStream on: String new.
• Smalltalk keys inject: aStream
into: [:cumul :aString| cumul nextPutAll: aString. cumul]
Streams, Blocks, and Optimization (ii)
S.Ducasse 15
• InstanceVariables:
• method <CompiledBlock>
• outerContext <Context | nil>
• copiedValues <Object | Array | nil>
• "Clean" closure with no references to anything from outer scopes.A clean
closure has outerContext = nil and copiedValues = empty Array.
• "Copying" closure that copies immutable values from outer scopes when the
closure is created.A copying closure has outerContext = nil and copiedValues =
Object or Array.
• "Full" closure that retains a reference to the next outer scope.A full closure has
outerContext ~= nil and copiedValues = nil.
• As an optimization, copiedValues holds the single copied value if there is exactly
one, or an Array of values if there is more than one. Note that if there is a
single copied value, the value being copied can be nil, so testing for nil in
copiedValues is not a reliable means of classifying closures.The way to check
whether a closure has copied values is to ask its method whether
numCopiedValues > 0.
BlockClosure Class Comments
S.Ducasse 16
• Now if we use a stream for the Smalltalk keys we can
avoid an iteration method.With whileFalse: that is
inlined the block itself will be inlined.
• |aReadStream aWriteStream|
• aReadStream := ReadStream on: Smalltalk keys asArray.
• aWriteStream := WriteStream on: String new.
• [aReadStream atEnd] whileFalse: [aWriteStream nextPutAll: a ReadStream
next].
• OptimizationYes, but Readibility First
Streams, Blocks, and Optimization (iii)
S.Ducasse 17
Summary
Blocks
Try to define clean blocks

Más contenido relacionado

La actualidad más candente

Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingC4Media
 
Multithreading done right
Multithreading done rightMultithreading done right
Multithreading done rightPlatonov Sergey
 
Tutorial 5 adding more nodes
Tutorial 5   adding more nodes Tutorial 5   adding more nodes
Tutorial 5 adding more nodes Mohd Batati
 
Network programming using python
Network programming using pythonNetwork programming using python
Network programming using pythonAli Nezhad
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programmingRodolfo Finochietti
 
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Codemotion
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Stackless Python 101
Stackless Python 101Stackless Python 101
Stackless Python 101guest162fd90
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)Andrey Karpov
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Codemotion
 
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Emery Berger
 
Concurrency: Rubies, Plural
Concurrency: Rubies, PluralConcurrency: Rubies, Plural
Concurrency: Rubies, PluralEleanor McHugh
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, pluralehuard
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 

La actualidad más candente (20)

Rust: Unlocking Systems Programming
Rust: Unlocking Systems ProgrammingRust: Unlocking Systems Programming
Rust: Unlocking Systems Programming
 
Multithreading done right
Multithreading done rightMultithreading done right
Multithreading done right
 
Tutorial 5 adding more nodes
Tutorial 5   adding more nodes Tutorial 5   adding more nodes
Tutorial 5 adding more nodes
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
Network programming using python
Network programming using pythonNetwork programming using python
Network programming using python
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Thread
ThreadThread
Thread
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
Stackless Python 101
Stackless Python 101Stackless Python 101
Stackless Python 101
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
 
Concurrency: Rubies, Plural
Concurrency: Rubies, PluralConcurrency: Rubies, Plural
Concurrency: Rubies, Plural
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, plural
 
Secure code 3rd_party_libs
Secure code 3rd_party_libsSecure code 3rd_party_libs
Secure code 3rd_party_libs
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 

Destacado (20)

11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Stoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvwStoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvw
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
 
Stoop 400-metaclass only
Stoop 400-metaclass onlyStoop 400-metaclass only
Stoop 400-metaclass only
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
10 reflection
10 reflection10 reflection
10 reflection
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 

Similar a Stoop 300-block optimizationinvw

Ruby basics ||
Ruby basics ||Ruby basics ||
Ruby basics ||datt30
 
Mathemetics module
Mathemetics moduleMathemetics module
Mathemetics modulemanikanta361
 
CUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesCUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesSubhajit Sahu
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysBlue Elephant Consulting
 
Ruby basics || updated
Ruby basics || updatedRuby basics || updated
Ruby basics || updateddatt30
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
C sharp 8.0 new features
C sharp 8.0 new featuresC sharp 8.0 new features
C sharp 8.0 new featuresMSDEVMTL
 
C sharp 8.0 new features
C sharp 8.0 new featuresC sharp 8.0 new features
C sharp 8.0 new featuresMiguel Bernard
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coveragePushpa Yakkala
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingOrtus Solutions, Corp
 
Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocksishwarya516
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operationsSmee Kaem Chann
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksMarcus Denker
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#Rohit Rao
 

Similar a Stoop 300-block optimizationinvw (20)

Ruby basics ||
Ruby basics ||Ruby basics ||
Ruby basics ||
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
Mathemetics module
Mathemetics moduleMathemetics module
Mathemetics module
 
5 Statements and Control Structures
5 Statements and Control Structures5 Statements and Control Structures
5 Statements and Control Structures
 
CUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesCUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : Notes
 
Intro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & ArraysIntro To C++ - Class #18: Vectors & Arrays
Intro To C++ - Class #18: Vectors & Arrays
 
Stoop 390-instruction stream
Stoop 390-instruction streamStoop 390-instruction stream
Stoop 390-instruction stream
 
Ruby basics || updated
Ruby basics || updatedRuby basics || updated
Ruby basics || updated
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
C sharp 8.0 new features
C sharp 8.0 new featuresC sharp 8.0 new features
C sharp 8.0 new features
 
C sharp 8.0 new features
C sharp 8.0 new featuresC sharp 8.0 new features
C sharp 8.0 new features
 
System verilog coverage
System verilog coverageSystem verilog coverage
System verilog coverage
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocks
 
Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 

Más de The World of Smalltalk (20)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Último

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Stoop 300-block optimizationinvw

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ Blocks and Optimization in VW
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 [ :x :y | |tmp| ...] value value: value: value: value: value: value: valueWithArguments: •InVisualWorks there are four types of blocks: • Full Blocks • Copying Blocks • Clean Blocks • Inlined Blocks •The programmer does not have to explicitly mention. •Inferred by the compiler. However, knowing the subtle differences allows the programmer to write more efficient code. Blocks and Optimization inVW
  • 4. S.Ducasse 4 • Read and assign temporary variables. • Block containing explicit return ^. • Compiled in a BlockClosure. • Evaluation by the creation of an explicit MethodContext or BlockContext object instead of using a pseudo-object contained in the stack. • Most costly • Instead of: • m1: arg1 m1: arg1 • arg1 isNil ^ arg1 isNil • ifTrue: [^ 1] ifTrue: [1] • ifTrue: [^ 2] ifTrue: [2] Full Blocks
  • 5. S.Ducasse 5 • Read temporary variables but do not assign them. • No explicit return. • Access instance variables of self and assign them. • Not compiled into a BlockClosure. • They are compiled by copying every access into the block, thus avoiding explicit references to a context where the copied variables appear. • Their arguments and temporaries are merged into the enclosing method’s context as “compiler-generated temporaries”. Copying Blocks
  • 6. S.Ducasse 6 • Contain only reference block temporary variables or global variables. • No reference to self or to instance variables. • nodes do: [:each | each name = #stef] • nodes select: [:each | each isLocal] Clean Blocks
  • 7. S.Ducasse 7 • Code of certain methods, like whileFalse: ifTrue:, is directly inlined into the code of the calling method. • The literal blocks (without arguments) passed as argument to such methods are also inlined in the byte-code of the calling method. • Inlined methods are whileTrue, whileTrue:, whileFalse, whileFalse:, and: or:, ifTrue:, ifFalse:, ifTrue:ifFalse:, ifFalse:ifTrue:, to:do:, to:do:by: • Look in MessageNode>>transform* methods to see the inlining Inlined Blocks
  • 8. S.Ducasse 8 • testInLined • 1 to: 5 do: [:x| ] • Compiled into : • | t1 | • t1 := 1. • [t1 <= 5] whileTrue: [t1 := t1 + 1]. • But no BlockClosure is created (look into the byte codes) Inlined Blocks
  • 9. S.Ducasse 9 • Instead of: • |t| • [:x | t := x foo] value: 1. • t := t * 2. • ^t • The reference to t inside the block makes it at least a copying block. • t := makes it full. • With the following we have a clean block. • |t| • t := [:x | x foo] value:1. • t := t * 2. • ^t From Full to Copy
  • 10. S.Ducasse 10 • Full blocks are evaluated in a separate context. • The following code evaluates to false: • |outerContext answer| • outerContext := thisContext. • (1 to: 1) do: [:i | answer := thisContext == outerContext]. • ^answer • But the following evaluates to true because: to:do: is an inlined block • |outerContext answer| • outerContext := thisContext. • 1 to: 1 do: [:i | answer := thisContext == outerContext]. • ^answer Contexts
  • 11. S.Ducasse 11 • Instead of: • |maxNumber| • maxNumber := 0. • #(1 2 43 56 2 49 3 2 0 ) do: [:each| maxNumber := each max: maxNumber]. • ^maxNumber • Write • #(1 2 43 56 2 49 3 2 0 ) inject: 0 into: [:maxNumber :ele| maxNumber max: ele] • no need for a temporary variable • full block becomes a clean block inject:into:
  • 12. S.Ducasse 12 • str1 , str2 creates a new structure in which str1 and str2 elements are stored SequenceableCollection>>, aSequenceableCollection "Answer a copy of the receiver concatenated with the argument, a SequenceableCollection." ^self copyReplaceFrom: self size + 1 to: self size with: aSequenceableCollection SequenceableCollection>>copyReplaceFrom: start to: stop with: replacementCollection "Answer a copy of the receiver satisfying the following conditions: .." About String Concatenation
  • 13. S.Ducasse 13 • Suppose that we want to concatenate a pretty long list of strings, for example the keys of the Smalltalk dictionary. • |bigString| • bigString := String new. • Smalltalk keys do: [:aString | bigString := bigString, aString]. • Here the assignment of bigString leads to a Full Block • We can suppress the assignment like that and thus obtain a clean block • |aStream| • aStream:= WriteStream on: String new. • Smalltalk keys do: [:aString | aStream nextPutAll: aString]. Streams, Blocks, and Optimization
  • 14. S.Ducasse 14 • inject:into: allows us to suppress the reference to variables that are outside the block and to obtain a clean block. • |aStream| • aStream:= WriteStream on: String new. • Smalltalk keys inject: aStream into: [:cumul :aString| cumul nextPutAll: aString. cumul] Streams, Blocks, and Optimization (ii)
  • 15. S.Ducasse 15 • InstanceVariables: • method <CompiledBlock> • outerContext <Context | nil> • copiedValues <Object | Array | nil> • "Clean" closure with no references to anything from outer scopes.A clean closure has outerContext = nil and copiedValues = empty Array. • "Copying" closure that copies immutable values from outer scopes when the closure is created.A copying closure has outerContext = nil and copiedValues = Object or Array. • "Full" closure that retains a reference to the next outer scope.A full closure has outerContext ~= nil and copiedValues = nil. • As an optimization, copiedValues holds the single copied value if there is exactly one, or an Array of values if there is more than one. Note that if there is a single copied value, the value being copied can be nil, so testing for nil in copiedValues is not a reliable means of classifying closures.The way to check whether a closure has copied values is to ask its method whether numCopiedValues > 0. BlockClosure Class Comments
  • 16. S.Ducasse 16 • Now if we use a stream for the Smalltalk keys we can avoid an iteration method.With whileFalse: that is inlined the block itself will be inlined. • |aReadStream aWriteStream| • aReadStream := ReadStream on: Smalltalk keys asArray. • aWriteStream := WriteStream on: String new. • [aReadStream atEnd] whileFalse: [aWriteStream nextPutAll: a ReadStream next]. • OptimizationYes, but Readibility First Streams, Blocks, and Optimization (iii)
  • 17. S.Ducasse 17 Summary Blocks Try to define clean blocks