SlideShare a Scribd company logo
©2015 GlobalLogic Inc.
2
Java Performance Boost
By Andrii Antilikatorov
3
4
Optimize or not optimize?
5
Rule
6
7
8
Avoid usage byte[] to String constructor (Java 6)
9
Avoid usage byte[] to String constructor (Java 6)
• Update to Java 7 or later
• Minimize usage of constructor
10
Understanding of “switch on String”
11
String Internation
String
String
String
String
String
String
String
String
String
String
StringString
Do not use String.intern() on Java 6
Internation is efficient on Java 7 and above
Works great in multithreaded code
JVM string pool is NOT thread local
String
12
String Deduplication
Available from Java 8 update 20
Requires G1 collector to be
enabled. Optional phase of G1.
Unlikely to run on the loaded systems
Processes only strings that survived
after few garbage collections
Doesn’t mean you shouldn’t use
internation
String
String
String
String
String
String
String
String
String
String
StringString
String
13
String Deduplication
Available from Java 8 update 20
Requires G1 collector to be
enabled. Optional phase of G1.
Unlikely to run on the loaded systems
Processes only strings that survived
after few garbage collections
Doesn’t mean you shouldn’t use
internation
String
String
String
String
String
String
String
String
String
String
StringString
String
String before Java 7 update 6
• char [] symbols;
• Offset
• Count
• Hash code
14
String Deduplication
Available from Java 8 update 20
Requires G1 collector to be
enabled. Optional phase of G1.
Unlikely to run on the loaded systems
Processes only strings that survived
after few garbage collections
Doesn’t mean you shouldn’t use
internation
String
String
String
String
String
String
String
String
String
String
StringString
String
String before Java 7 update 6
• char [] symbols;
• Offset
• Count
• Hash code
This is very very long string which consumes a lot of memory…
This is very very long string which consumes a lot of memory…
15
String Deduplication
Available from Java 8 update 20
Requires G1 collector to be
enabled. Optional phase of G1.
Unlikely to run on the loaded systems
Processes only strings that survived
after few garbage collections
Doesn’t mean you shouldn’t use
internation
String
String
String
String
String
String
String
String
String
String
StringString
String
String after Java 7 update 6
• char [] symbols;
• Hash code
16
String Deduplication
Available from Java 8 update 20
Requires G1 collector to be
enabled. Optional phase of G1.
Unlikely to run on the loaded systems
Processes only strings that survived
after few garbage collections
Doesn’t mean you shouldn’t use
internation
String
String
String
String
String
String
String
String
String
String
StringString
String
• Serial
• Parallel
• Concurrent Mark Sweep (CMS)
• Garbage-First (G1)
17
Avoid heavy logic in static constructors
18
Avoid heavy logic in static constructors
19
Avoid heavy logic in static constructors
20
Problem with inner classes
21
Problem with inner classes
22
Cost of method calls
invokestatic
invokevirtual
invokeinterface
invokespecial
23
Cost of method calls
invokestatic
invokevirtual
invokeinterface
invokespecial
Dependency Injection
24
Maps & Sets - Hints
Set:
Map:
25
Maps & Sets - Hints
• emptyList/emptyMap/emptySet - for empty
collections
• singletonList/singletonMap/singleton
Set - for collections containing a single
element/pair
26
Performance of Date/Time entities
java.util.Date java.util.GregorianCalendar
27
Performance of Date/Time entities
24 bytes 448 bytes
java.util.Date java.util.GregorianCalendar
28
Performance of Date/Time entities
24 bytes 448 bytes
java.util.Date java.util.GregorianCalendar
29
Synchronized block or synchronized method?
30
Synchronized block or synchronized method?
0: aload_0
1: getfield
2: nop
3: iconst_m1
4: ireturn
31
Synchronized block or synchronized method?
0: aload_0
1: dup
2: astore_1
3: monitorenter
4: aload_0
5: getfield
6: nop
7: iconst_m1
8: aload_1
9: monitorexit
10: ireturn
11: astore_2
12: aload_1
13: monitorexit
14: aload_2
15: athrow
32
Thread-safe variants of List and Set
Manual synchronization of
operations with collections
Use CopyOnWrite*
collections
33
Synchronized or volatile variables?
Volatile variables are less expensive than synchronized
Volatile are thread-safe for atomic operations
Volatile acquires lock on variable, therefore not thread- safe
for non-atomic operations
Synchronized blocks have no performance impact if no
synchronization required
34
Synchronized or volatile variables?
MESI Protocol
• Modified
• Exclusive
• Shared
• Invalid
35
Summary
Architecture first
Remember rule 80/20
Don’t try to write ideal code from the beginning
Don’t create bicycles
Don’t optimize for particular platform
©2015 GlobalLogic Inc.

More Related Content

PPTX
.NET Performance Boost
PPTX
Java Performance Boost
ODP
Java GC, Off-heap workshop
PDF
Jvm operation casual talks
PPT
InfiniBand in the Lab (vSphere 5.5) VMworld 2013 Barcelona vBrownbag Tech Talk
PDF
InfiniBand in the Lab (London VMUG)
PPT
Find bottleneck and tuning in Java Application
PDF
JVM and Garbage Collection Tuning
.NET Performance Boost
Java Performance Boost
Java GC, Off-heap workshop
Jvm operation casual talks
InfiniBand in the Lab (vSphere 5.5) VMworld 2013 Barcelona vBrownbag Tech Talk
InfiniBand in the Lab (London VMUG)
Find bottleneck and tuning in Java Application
JVM and Garbage Collection Tuning

What's hot (20)

PDF
Tiered Compilation in Hotspot JVM
PDF
GraalVm and Quarkus
PDF
Fight with Metaspace OOM
PDF
Jvm internals
PDF
The need for speed. What is GraalVM? – 4Developers Wrocław 2019
PDF
Jvm internals 2015 - CorkJUG
PDF
Tech Talk #4 : Multi - threading and GCD ( grand central dispatch ) in iOS - ...
PDF
淺談 Java GC 原理、調教和 新發展
PDF
Eclipse Day India 2015 - Java bytecode analysis and JIT
PDF
Lock free programming- pro tips
PDF
Tools for Metaspace
KEY
Blocks & Grand Central Dispatch
PDF
Grand Central Dispatch - iOS Conf SG 2015
PDF
LCU14 209- LLVM Linux
PDF
Reactive Vert.x
PDF
Advanced Percona XtraDB Cluster in a nutshell... la suite
PDF
GCD and OperationQueue.
PDF
Multimaster
PDF
Introduction to Vacuum Freezing and XID
KEY
Concurrent Programming Using the Disruptor
Tiered Compilation in Hotspot JVM
GraalVm and Quarkus
Fight with Metaspace OOM
Jvm internals
The need for speed. What is GraalVM? – 4Developers Wrocław 2019
Jvm internals 2015 - CorkJUG
Tech Talk #4 : Multi - threading and GCD ( grand central dispatch ) in iOS - ...
淺談 Java GC 原理、調教和 新發展
Eclipse Day India 2015 - Java bytecode analysis and JIT
Lock free programming- pro tips
Tools for Metaspace
Blocks & Grand Central Dispatch
Grand Central Dispatch - iOS Conf SG 2015
LCU14 209- LLVM Linux
Reactive Vert.x
Advanced Percona XtraDB Cluster in a nutshell... la suite
GCD and OperationQueue.
Multimaster
Introduction to Vacuum Freezing and XID
Concurrent Programming Using the Disruptor
Ad

Viewers also liked (10)

PPTX
Nicety of Java 8 Multithreading
PPTX
Java 8 Intro - Core Features
PDF
How to Learn a Programming Language in 25 Minutes
PDF
Take a Look at Akka-Java
PPTX
Object-Relational Mapping for Dummies
PPTX
Spring vs EJB
PPTX
Commercial Development from the Inside
PDF
Big Audience at Scale — Spark and Big Data
PPTX
Battle for Code Quality - A Story of One Java Project
PPTX
Антон Зотов - "Від інженера до AVP. Мій досвід побудови кар’єри в ІТ" Kharkiv...
Nicety of Java 8 Multithreading
Java 8 Intro - Core Features
How to Learn a Programming Language in 25 Minutes
Take a Look at Akka-Java
Object-Relational Mapping for Dummies
Spring vs EJB
Commercial Development from the Inside
Big Audience at Scale — Spark and Big Data
Battle for Code Quality - A Story of One Java Project
Антон Зотов - "Від інженера до AVP. Мій досвід побудови кар’єри в ІТ" Kharkiv...
Ad

Similar to Java Performance Boost (20)

PDF
Lifecycle of a JIT compiled code
PDF
Code lifecycle in the jvm - TopConf Linz
PPTX
Fundamentals of java --- version 2
PPT
Java for the Beginners
PDF
Native Java with GraalVM
ODP
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
PPTX
What is so great about Java 6
PDF
Running JavaScript Efficiently in a Java World
PDF
JVM Internals (2015)
PDF
From V8 to Modern Compilers
PDF
JCConf 2018 - Retrospect and Prospect of Java
PDF
Head toward Java 14 and Java 15 #LINE_DM
PDF
GraalVM - OpenSlava 2019-10-18
PDF
Isomorphic JavaScript with Nashorn
PDF
How the HotSpot and Graal JVMs execute Java Code
PDF
JRuby 9000 - Taipei Ruby User's Group 2015
PPTX
PDF
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
PDF
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
PPTX
Java Jit. Compilation and optimization by Andrey Kovalenko
Lifecycle of a JIT compiled code
Code lifecycle in the jvm - TopConf Linz
Fundamentals of java --- version 2
Java for the Beginners
Native Java with GraalVM
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
What is so great about Java 6
Running JavaScript Efficiently in a Java World
JVM Internals (2015)
From V8 to Modern Compilers
JCConf 2018 - Retrospect and Prospect of Java
Head toward Java 14 and Java 15 #LINE_DM
GraalVM - OpenSlava 2019-10-18
Isomorphic JavaScript with Nashorn
How the HotSpot and Graal JVMs execute Java Code
JRuby 9000 - Taipei Ruby User's Group 2015
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
Java Jit. Compilation and optimization by Andrey Kovalenko

More from GlobalLogic Ukraine (20)

PDF
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
PPTX
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
PDF
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
PDF
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
PDF
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
PDF
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
PPTX
Штучний інтелект як допомога в навчанні, а не замінник.pptx
PPTX
Задачі AI-розробника як застосовується штучний інтелект.pptx
PPTX
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
PDF
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
PDF
JavaScript Community Webinar #14 "Why Is Git Rebase?"
PDF
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
PPTX
Страх і сила помилок - IT Inside від GlobalLogic Education
PDF
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
PDF
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
PDF
“How to Secure Your Applications With a Keycloak?
PDF
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
PPTX
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
PDF
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
PDF
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
GlobalLogic JavaScript Community Webinar #21 “Інтерв’ю без заспокійливих”
Deadlocks in SQL - Turning Fear Into Understanding (by Sergii Stets)
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
Штучний інтелект як допомога в навчанні, а не замінник.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
JavaScript Community Webinar #14 "Why Is Git Rebase?"
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
Страх і сила помилок - IT Inside від GlobalLogic Education
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
“How to Secure Your Applications With a Keycloak?
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"

Recently uploaded (20)

PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
history of c programming in notes for students .pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
System and Network Administraation Chapter 3
PPTX
Introduction to Artificial Intelligence
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
System and Network Administration Chapter 2
Designing Intelligence for the Shop Floor.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Understanding Forklifts - TECH EHS Solution
history of c programming in notes for students .pptx
top salesforce developer skills in 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo Companies in India – Driving Business Transformation.pdf
System and Network Administraation Chapter 3
Introduction to Artificial Intelligence
Softaken Excel to vCard Converter Software.pdf
Digital Strategies for Manufacturing Companies
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Nekopoi APK 2025 free lastest update
2025 Textile ERP Trends: SAP, Odoo & Oracle
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
L1 - Introduction to python Backend.pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
System and Network Administration Chapter 2

Java Performance Boost

  • 2. 2 Java Performance Boost By Andrii Antilikatorov
  • 3. 3
  • 4. 4 Optimize or not optimize?
  • 6. 6
  • 7. 7
  • 8. 8 Avoid usage byte[] to String constructor (Java 6)
  • 9. 9 Avoid usage byte[] to String constructor (Java 6) • Update to Java 7 or later • Minimize usage of constructor
  • 11. 11 String Internation String String String String String String String String String String StringString Do not use String.intern() on Java 6 Internation is efficient on Java 7 and above Works great in multithreaded code JVM string pool is NOT thread local String
  • 12. 12 String Deduplication Available from Java 8 update 20 Requires G1 collector to be enabled. Optional phase of G1. Unlikely to run on the loaded systems Processes only strings that survived after few garbage collections Doesn’t mean you shouldn’t use internation String String String String String String String String String String StringString String
  • 13. 13 String Deduplication Available from Java 8 update 20 Requires G1 collector to be enabled. Optional phase of G1. Unlikely to run on the loaded systems Processes only strings that survived after few garbage collections Doesn’t mean you shouldn’t use internation String String String String String String String String String String StringString String String before Java 7 update 6 • char [] symbols; • Offset • Count • Hash code
  • 14. 14 String Deduplication Available from Java 8 update 20 Requires G1 collector to be enabled. Optional phase of G1. Unlikely to run on the loaded systems Processes only strings that survived after few garbage collections Doesn’t mean you shouldn’t use internation String String String String String String String String String String StringString String String before Java 7 update 6 • char [] symbols; • Offset • Count • Hash code This is very very long string which consumes a lot of memory… This is very very long string which consumes a lot of memory…
  • 15. 15 String Deduplication Available from Java 8 update 20 Requires G1 collector to be enabled. Optional phase of G1. Unlikely to run on the loaded systems Processes only strings that survived after few garbage collections Doesn’t mean you shouldn’t use internation String String String String String String String String String String StringString String String after Java 7 update 6 • char [] symbols; • Hash code
  • 16. 16 String Deduplication Available from Java 8 update 20 Requires G1 collector to be enabled. Optional phase of G1. Unlikely to run on the loaded systems Processes only strings that survived after few garbage collections Doesn’t mean you shouldn’t use internation String String String String String String String String String String StringString String • Serial • Parallel • Concurrent Mark Sweep (CMS) • Garbage-First (G1)
  • 17. 17 Avoid heavy logic in static constructors
  • 18. 18 Avoid heavy logic in static constructors
  • 19. 19 Avoid heavy logic in static constructors
  • 22. 22 Cost of method calls invokestatic invokevirtual invokeinterface invokespecial
  • 23. 23 Cost of method calls invokestatic invokevirtual invokeinterface invokespecial Dependency Injection
  • 24. 24 Maps & Sets - Hints Set: Map:
  • 25. 25 Maps & Sets - Hints • emptyList/emptyMap/emptySet - for empty collections • singletonList/singletonMap/singleton Set - for collections containing a single element/pair
  • 26. 26 Performance of Date/Time entities java.util.Date java.util.GregorianCalendar
  • 27. 27 Performance of Date/Time entities 24 bytes 448 bytes java.util.Date java.util.GregorianCalendar
  • 28. 28 Performance of Date/Time entities 24 bytes 448 bytes java.util.Date java.util.GregorianCalendar
  • 29. 29 Synchronized block or synchronized method?
  • 30. 30 Synchronized block or synchronized method? 0: aload_0 1: getfield 2: nop 3: iconst_m1 4: ireturn
  • 31. 31 Synchronized block or synchronized method? 0: aload_0 1: dup 2: astore_1 3: monitorenter 4: aload_0 5: getfield 6: nop 7: iconst_m1 8: aload_1 9: monitorexit 10: ireturn 11: astore_2 12: aload_1 13: monitorexit 14: aload_2 15: athrow
  • 32. 32 Thread-safe variants of List and Set Manual synchronization of operations with collections Use CopyOnWrite* collections
  • 33. 33 Synchronized or volatile variables? Volatile variables are less expensive than synchronized Volatile are thread-safe for atomic operations Volatile acquires lock on variable, therefore not thread- safe for non-atomic operations Synchronized blocks have no performance impact if no synchronization required
  • 34. 34 Synchronized or volatile variables? MESI Protocol • Modified • Exclusive • Shared • Invalid
  • 35. 35 Summary Architecture first Remember rule 80/20 Don’t try to write ideal code from the beginning Don’t create bicycles Don’t optimize for particular platform