SlideShare a Scribd company logo
1 of 36
SCALA PROFILING
                             (for Java developers)




                                                     Filippo Pacifici


mercoledì 23 maggio 12
Who am I
                    • Filippo Pacifici
                     • Twitter: OddId_
                     • mail: filippo.pacifici@gmail.com
                     • Blog: http://outofmemoryblog.blogspot.com
                    • One of the 9M devs thinking Java is not so bad
                     • recently started looking at Scala
mercoledì 23 maggio 12
What’s this all about?
                    • Apply Java profiling methods to Scala
                         programs
                         • How do we deal with performance in
                           Java?
                         • Is it the same in Scala?
                    • How do we optimize a JVM for Scala
                         applications?


mercoledì 23 maggio 12
Java profiling 101



mercoledì 23 maggio 12
Java profiling 101

                    • Goals:
                     • troubleshoot performance problems
                     • estimate application performance
                     • estimate application scalability

mercoledì 23 maggio 12
Java profiling 101
                    • Ehi, I use Scala, why should I care about Java
                         profiling?
                         • Scala compiled in byte code and runs in a
                           JVM
                         • We can profile a Scala application as it
                           was Java
                         • We can use the same tools
                         • I am not aware of alternatives
mercoledì 23 maggio 12
Java methods profiling
 •      Tracks methods invocations

       •      Runtime instrumentation

       •      Time analysis




mercoledì 23 maggio 12
Java memory profiling
       •      Dumps heap content

             •     Browse objects in the heap

             •     Memory usage analysis




mercoledì 23 maggio 12
Profiling tools
                    • Method profiling
                     • Java Visual VM (embedded in JDK)
                     • Yourkit, Dynatrace, etc.
                    • Memory profiling
                     • Eclipse MAT (www.eclipse.org/
                           mat)
                         • Yourkit, Dynatrace, etc.
mercoledì 23 maggio 12
Back to Scala...

                    • We won’t find Scala specific constructs
                     • Need to know how Scala is translated
                           into bytecode
                    • Goals:
                     • Identify methods generated by Scala
                           compilers
                         • Characterize Scala data structures in
                           memory
mercoledì 23 maggio 12
Scala Functions



mercoledì 23 maggio 12
Short discouraging
                         comparative demo



mercoledì 23 maggio 12
Scala functions vs byte code

                    • Classic functions converted in methods
                    • First class function do not exist in Java
                     • Anonymous classes extending
                           scala.runtime.AbstractFunction
                         • apply method to execute.

mercoledì 23 maggio 12
AbstractFunction
      •     AbstractFunction2

            •     takes 2 input parameters

      •     One apply method per
            combination of input and
            output types

            •     example apply.mcFID

                 •       F= returns float

                 •       I takes one Int

                 •       D takes one Double
mercoledì 23 maggio 12
AbstractFunction
                    • Find the call in the profile:


                • anonfun => instance of the anonymous class
                • main$1 => first anonymous class defined in
                         main method


mercoledì 23 maggio 12
Functions in the heap

                    • Each instance of AbstractFunction present
                         in the heap
                         • Very small impact
                         • Stateless


mercoledì 23 maggio 12
Where do we use them?
                    • Our program did not contain any anonymous
                         function, right?
                    • AbstractFunction used:
                     • For first class functions
                     • For closures
                     • For partially applied functions
                     • To manage for loops blocks
                     • To manage filter logic in for loops
mercoledì 23 maggio 12
Performance impact
                    • Is this a performance impact?
                     • Scala compiler performs optimizations:
                        • Same anonymous functions reused
                           (avoid multiple instantiations)
                         • Anonymous functions doing the same
                           thing are shared
                         • Attention to partially applied:
                          • New function created.
mercoledì 23 maggio 12
Some examples



mercoledì 23 maggio 12
Scala data structures
                             (Collections in heap dump)




mercoledì 23 maggio 12
Scala Lists
                    • A Scala view:
                     • Linked lists (single link)
                     • abstract class List + two case classes: ::
                         and Nil




mercoledì 23 maggio 12
Scala Lists
                    • A byte code view:
                     • Case classes become inner classes:
                       • :: becomes $colon$colon
                       • Nil becomes Nil



mercoledì 23 maggio 12
Scala Lists
                • Heads and elements have the same type




mercoledì 23 maggio 12
Scala Lists

                    • What about mutable lists?
                     • ListBuffer
                       • Wrapper on a Linked List
                       • Keeps an additional reference to the
                          last element: last0



mercoledì 23 maggio 12
Scala Sets
                    • Immutable sets
                     • scala.collection.immutable.Set
                     • Case classes for different sizes
                     • HashSet over 5 elements


mercoledì 23 maggio 12
Scala Maps

                    • Immutable:
                     • small number of elements:
                           scala.collections.immutable.Map$MapN
                         • N = number of elements
                         • over 5 elements:
                           scala.collection.immutable.HashMap
                    • Mutable: scala.collection.mutable.HashMap
mercoledì 23 maggio 12
Map and Sets examples



mercoledì 23 maggio 12
Primitive types boxing



mercoledì 23 maggio 12
Primitive types and
                               generics
                    • Type parameters cannot be primitive in
                         generic types.
                         • Scala systematically boxes and unboxes
                           them to Object
                         • scala.runtime.BoxesRunTime methods


mercoledì 23 maggio 12
Basic tuning tips



mercoledì 23 maggio 12
Exploit tail recursion
                    • Long recursion
                     • Long stack
                     • Performance impact on stack size
                    • Scala compiler recognizes tail recursion
                     • Recursive call must be the last operation
                           of the method
                         • Scala transforms it into iterative form

mercoledì 23 maggio 12
Can’t exploit tail
                               recursion?
                    • If (and only if) you run out of stack space
                         (frequent java.lang.StackOverflowError):
                         • -Xss JVM option sets stack size
                         • example: -Xss2048k
                         • Normally limited at OS level
                         • Each thread statically allocates stack size:
                          • pay attention
mercoledì 23 maggio 12
Memory structure
                    • Optimize for small, short lived objects
                     • Anonymous functions:
                       • small
                       • frequently instantiated
                     • Use a big young space
                       • GC is fast and frequent
                       • Objects do not get promoted
mercoledì 23 maggio 12
Memory structure

                    • What about the perm gen?
                     • Anonymous classes reused
                     • No insane usage of proxies
                     • No specific issues

mercoledì 23 maggio 12
Which GC should I use?
                    • Depends on your application requirements
                     • The same consideration done for Java
                         still hold
                         • Need throughput : parallel GC
                         • Need response time : CMS
                         • You are brave : G1
mercoledì 23 maggio 12
Questions?



mercoledì 23 maggio 12

More Related Content

What's hot

Project in malware analysis:C2C
Project in malware analysis:C2CProject in malware analysis:C2C
Project in malware analysis:C2CFabrizio Farinacci
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblySam Bowne
 
Lineにおけるspring frameworkの活用
Lineにおけるspring frameworkの活用Lineにおけるspring frameworkの活用
Lineにおけるspring frameworkの活用Tokuhiro Matsuno
 
CNIT 126: 8: Debugging
CNIT 126: 8: DebuggingCNIT 126: 8: Debugging
CNIT 126: 8: DebuggingSam Bowne
 
Convolutional neural network
Convolutional neural networkConvolutional neural network
Convolutional neural networkMojammilHusain
 
A Simple Framework for Contrastive Learning of Visual Representations
A Simple Framework for Contrastive Learning of Visual RepresentationsA Simple Framework for Contrastive Learning of Visual Representations
A Simple Framework for Contrastive Learning of Visual RepresentationsSeunghyun Hwang
 
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...MITRE - ATT&CKcon
 
Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Kenjiro Kubota
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentRishabh Soni
 
Argoによる機械学習実行基盤の構築・運用からみえてきたこと
Argoによる機械学習実行基盤の構築・運用からみえてきたことArgoによる機械学習実行基盤の構築・運用からみえてきたこと
Argoによる機械学習実行基盤の構築・運用からみえてきたことShinsaku Kono
 
Proof summit 2017 for slideshare
Proof summit 2017 for slideshareProof summit 2017 for slideshare
Proof summit 2017 for slideshareKeisuke Yahata
 
脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよ脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよMasakazu Ikeda
 
データ可視化勉強会
データ可視化勉強会データ可視化勉強会
データ可視化勉強会Daichi Morifuji
 
Klocwork カスタムチェッカー紹介
Klocwork カスタムチェッカー紹介Klocwork カスタムチェッカー紹介
Klocwork カスタムチェッカー紹介Masaru Horioka
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblyPractical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblySam Bowne
 
Solrで日本語全文検索システムの構築と応用
Solrで日本語全文検索システムの構築と応用Solrで日本語全文検索システムの構築と応用
Solrで日本語全文検索システムの構築と応用Syuta Hashimoto
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事Wen-Tien Chang
 
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)C#で作ったプログラムのインストーラーをInnoSetupで作成(1)
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)Kenichi Yamada
 
презентация Moodle
презентация Moodleпрезентация Moodle
презентация Moodleksanka90
 
2022_sakura-yube_ddd.pdf
2022_sakura-yube_ddd.pdf2022_sakura-yube_ddd.pdf
2022_sakura-yube_ddd.pdftoshiki kawai
 

What's hot (20)

Project in malware analysis:C2C
Project in malware analysis:C2CProject in malware analysis:C2C
Project in malware analysis:C2C
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 Disassembly
 
Lineにおけるspring frameworkの活用
Lineにおけるspring frameworkの活用Lineにおけるspring frameworkの活用
Lineにおけるspring frameworkの活用
 
CNIT 126: 8: Debugging
CNIT 126: 8: DebuggingCNIT 126: 8: Debugging
CNIT 126: 8: Debugging
 
Convolutional neural network
Convolutional neural networkConvolutional neural network
Convolutional neural network
 
A Simple Framework for Contrastive Learning of Visual Representations
A Simple Framework for Contrastive Learning of Visual RepresentationsA Simple Framework for Contrastive Learning of Visual Representations
A Simple Framework for Contrastive Learning of Visual Representations
 
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...
MITRE ATT&CKcon 2.0: Zeek-based ATT&CK Metrics and Gap Analysis; Allan Thomso...
 
Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。
 
Object Oriented Approach for Software Development
Object Oriented Approach for Software DevelopmentObject Oriented Approach for Software Development
Object Oriented Approach for Software Development
 
Argoによる機械学習実行基盤の構築・運用からみえてきたこと
Argoによる機械学習実行基盤の構築・運用からみえてきたことArgoによる機械学習実行基盤の構築・運用からみえてきたこと
Argoによる機械学習実行基盤の構築・運用からみえてきたこと
 
Proof summit 2017 for slideshare
Proof summit 2017 for slideshareProof summit 2017 for slideshare
Proof summit 2017 for slideshare
 
脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよ脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよ
 
データ可視化勉強会
データ可視化勉強会データ可視化勉強会
データ可視化勉強会
 
Klocwork カスタムチェッカー紹介
Klocwork カスタムチェッカー紹介Klocwork カスタムチェッカー紹介
Klocwork カスタムチェッカー紹介
 
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in AssemblyPractical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
Practical Malware Analysis: Ch 6: Recognizing C Code Constructs in Assembly
 
Solrで日本語全文検索システムの構築と応用
Solrで日本語全文検索システムの構築と応用Solrで日本語全文検索システムの構築と応用
Solrで日本語全文検索システムの構築と応用
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)C#で作ったプログラムのインストーラーをInnoSetupで作成(1)
C#で作ったプログラムのインストーラーをInnoSetupで作成(1)
 
презентация Moodle
презентация Moodleпрезентация Moodle
презентация Moodle
 
2022_sakura-yube_ddd.pdf
2022_sakura-yube_ddd.pdf2022_sakura-yube_ddd.pdf
2022_sakura-yube_ddd.pdf
 

Viewers also liked

Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascadingjohnynek
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話tod esking
 
Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Emprende Futuro
 
Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Sameer Mathur
 
Fyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFranky Redant
 
Despierta Papa Despierta
Despierta Papa DespiertaDespierta Papa Despierta
Despierta Papa Despiertaguesta7eb4a
 
Top 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineTop 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineIAB México
 
Comunicado Numero 1 CIMI
Comunicado Numero 1 CIMIComunicado Numero 1 CIMI
Comunicado Numero 1 CIMIDesarrollo Sena
 
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)humanidadescolapias
 
México 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMéxico 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMarco González
 

Viewers also liked (20)

Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Scala test
Scala testScala test
Scala test
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話
 
Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Colaboración y Negocios Web 20
Colaboración y Negocios Web 20
 
Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6
 
Fyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-sls
 
Present redes lvg
Present redes lvgPresent redes lvg
Present redes lvg
 
Despierta Papa Despierta
Despierta Papa DespiertaDespierta Papa Despierta
Despierta Papa Despierta
 
Top 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineTop 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media Online
 
Felicitación navidad 2013
Felicitación navidad 2013Felicitación navidad 2013
Felicitación navidad 2013
 
Comunicado Numero 1 CIMI
Comunicado Numero 1 CIMIComunicado Numero 1 CIMI
Comunicado Numero 1 CIMI
 
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
 
LA CRÓNICA 636
LA CRÓNICA 636LA CRÓNICA 636
LA CRÓNICA 636
 
México 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMéxico 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad Loaeza
 
Building TV apps with Chromecast
Building TV apps with ChromecastBuilding TV apps with Chromecast
Building TV apps with Chromecast
 

Similar to Scala profiling

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Martijn Verburg
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 dcubeio
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
 
Project Lambda, JSR 335
Project Lambda, JSR 335Project Lambda, JSR 335
Project Lambda, JSR 335Martin Skurla
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Martijn Verburg
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance TuningBurke Libbey
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Futuremircodotta
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization김 한도
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaJohn Nestor
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Mike Slinn
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeksjutley
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 

Similar to Scala profiling (20)

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Project Lambda, JSR 335
Project Lambda, JSR 335Project Lambda, JSR 335
Project Lambda, JSR 335
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
My sql tutorial-oscon-2012
My sql tutorial-oscon-2012My sql tutorial-oscon-2012
My sql tutorial-oscon-2012
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance Tuning
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Future
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeks
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 

Recently uploaded

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Scala profiling

  • 1. SCALA PROFILING (for Java developers) Filippo Pacifici mercoledì 23 maggio 12
  • 2. Who am I • Filippo Pacifici • Twitter: OddId_ • mail: filippo.pacifici@gmail.com • Blog: http://outofmemoryblog.blogspot.com • One of the 9M devs thinking Java is not so bad • recently started looking at Scala mercoledì 23 maggio 12
  • 3. What’s this all about? • Apply Java profiling methods to Scala programs • How do we deal with performance in Java? • Is it the same in Scala? • How do we optimize a JVM for Scala applications? mercoledì 23 maggio 12
  • 5. Java profiling 101 • Goals: • troubleshoot performance problems • estimate application performance • estimate application scalability mercoledì 23 maggio 12
  • 6. Java profiling 101 • Ehi, I use Scala, why should I care about Java profiling? • Scala compiled in byte code and runs in a JVM • We can profile a Scala application as it was Java • We can use the same tools • I am not aware of alternatives mercoledì 23 maggio 12
  • 7. Java methods profiling • Tracks methods invocations • Runtime instrumentation • Time analysis mercoledì 23 maggio 12
  • 8. Java memory profiling • Dumps heap content • Browse objects in the heap • Memory usage analysis mercoledì 23 maggio 12
  • 9. Profiling tools • Method profiling • Java Visual VM (embedded in JDK) • Yourkit, Dynatrace, etc. • Memory profiling • Eclipse MAT (www.eclipse.org/ mat) • Yourkit, Dynatrace, etc. mercoledì 23 maggio 12
  • 10. Back to Scala... • We won’t find Scala specific constructs • Need to know how Scala is translated into bytecode • Goals: • Identify methods generated by Scala compilers • Characterize Scala data structures in memory mercoledì 23 maggio 12
  • 12. Short discouraging comparative demo mercoledì 23 maggio 12
  • 13. Scala functions vs byte code • Classic functions converted in methods • First class function do not exist in Java • Anonymous classes extending scala.runtime.AbstractFunction • apply method to execute. mercoledì 23 maggio 12
  • 14. AbstractFunction • AbstractFunction2 • takes 2 input parameters • One apply method per combination of input and output types • example apply.mcFID • F= returns float • I takes one Int • D takes one Double mercoledì 23 maggio 12
  • 15. AbstractFunction • Find the call in the profile: • anonfun => instance of the anonymous class • main$1 => first anonymous class defined in main method mercoledì 23 maggio 12
  • 16. Functions in the heap • Each instance of AbstractFunction present in the heap • Very small impact • Stateless mercoledì 23 maggio 12
  • 17. Where do we use them? • Our program did not contain any anonymous function, right? • AbstractFunction used: • For first class functions • For closures • For partially applied functions • To manage for loops blocks • To manage filter logic in for loops mercoledì 23 maggio 12
  • 18. Performance impact • Is this a performance impact? • Scala compiler performs optimizations: • Same anonymous functions reused (avoid multiple instantiations) • Anonymous functions doing the same thing are shared • Attention to partially applied: • New function created. mercoledì 23 maggio 12
  • 20. Scala data structures (Collections in heap dump) mercoledì 23 maggio 12
  • 21. Scala Lists • A Scala view: • Linked lists (single link) • abstract class List + two case classes: :: and Nil mercoledì 23 maggio 12
  • 22. Scala Lists • A byte code view: • Case classes become inner classes: • :: becomes $colon$colon • Nil becomes Nil mercoledì 23 maggio 12
  • 23. Scala Lists • Heads and elements have the same type mercoledì 23 maggio 12
  • 24. Scala Lists • What about mutable lists? • ListBuffer • Wrapper on a Linked List • Keeps an additional reference to the last element: last0 mercoledì 23 maggio 12
  • 25. Scala Sets • Immutable sets • scala.collection.immutable.Set • Case classes for different sizes • HashSet over 5 elements mercoledì 23 maggio 12
  • 26. Scala Maps • Immutable: • small number of elements: scala.collections.immutable.Map$MapN • N = number of elements • over 5 elements: scala.collection.immutable.HashMap • Mutable: scala.collection.mutable.HashMap mercoledì 23 maggio 12
  • 27. Map and Sets examples mercoledì 23 maggio 12
  • 29. Primitive types and generics • Type parameters cannot be primitive in generic types. • Scala systematically boxes and unboxes them to Object • scala.runtime.BoxesRunTime methods mercoledì 23 maggio 12
  • 31. Exploit tail recursion • Long recursion • Long stack • Performance impact on stack size • Scala compiler recognizes tail recursion • Recursive call must be the last operation of the method • Scala transforms it into iterative form mercoledì 23 maggio 12
  • 32. Can’t exploit tail recursion? • If (and only if) you run out of stack space (frequent java.lang.StackOverflowError): • -Xss JVM option sets stack size • example: -Xss2048k • Normally limited at OS level • Each thread statically allocates stack size: • pay attention mercoledì 23 maggio 12
  • 33. Memory structure • Optimize for small, short lived objects • Anonymous functions: • small • frequently instantiated • Use a big young space • GC is fast and frequent • Objects do not get promoted mercoledì 23 maggio 12
  • 34. Memory structure • What about the perm gen? • Anonymous classes reused • No insane usage of proxies • No specific issues mercoledì 23 maggio 12
  • 35. Which GC should I use? • Depends on your application requirements • The same consideration done for Java still hold • Need throughput : parallel GC • Need response time : CMS • You are brave : G1 mercoledì 23 maggio 12