Mastering High Performance with Kotlin

Book description

Find out how to write Kotlin code without overhead and how to use different profiling tools and bytecode viewer to inspect expressions of Kotlin language.

About This Book
  • Apply modern Kotlin features to speed up processing and implement highly efficient and reliable codes.
  • Learn memory optimization, concurrency, multi-threading, scaling, and caching techniques to achieve high performance.
  • Learn how to prevent unnecessary overhead and use profiling tools to detect performance issues.
Who This Book Is For

This book is for Kotlin developers who would like to build reliable and high-performance applications. Prior Kotlin programming knowledge is assumed.

What You Will Learn
  • Understand the importance of high performance
  • Learn performance metrics
  • Learn popular design patterns currently being used in Kotlin
  • Understand how to apply modern Kotlin features to data processing
  • Learn how to use profling tools
  • Discover how to read bytecode
  • Learn to perform memory optimizations
  • Uncover approaches to the multithreading environment
In Detail

The ease with which we write applications has been increasing, but with it comes the need to address their performance. A balancing act between easily implementing complex applications and keeping their performance optimal is a present-day requirement In this book, we explore how to achieve this crucial balance, while developing and deploying applications with Kotlin.

The book starts by analyzing various Kotlin specifcations to identify those that have a potentially adverse effect on performance. Then, we move on to monitor techniques that enable us to identify performance bottlenecks and optimize performance metrics. Next, we look at techniques that help to us achieve high performance: memory optimization, concurrency, multi threading, scaling, and caching. We also look at fault tolerance solutions and the importance of logging. We'll also cover best practices of Kotlin programming that will help you to improve the quality of your code base.

By the end of the book, you will have gained some insight into various techniques and solutions that will help to create high-performance applications in the Kotlin environment

Style and approach

This book guides you through how to use profiling tools to detect performance issues and build high-performance applications in the Kotlin environment.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering High Performance with Kotlin
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Identifying Performance Bottlenecks
    1. Reasons for performance issues
      1. Memory management
      2. Garbage collection
      3. Working principles of the garbage collector
      4. Impacts of garbage collection
      5. Heap fragmentation
      6. Finalization
      7. Resource leaks
      8. Memory leaks
      9. String pool
    2. Memory model
      1. The problem of concurrency and parallelism
      2. Java Memory Model (JMM)
      3. Synchronization
    3. Slow rendering
      1. Device refresh rate
      2. Frame rate
    4. Summary
  7. Identifying Indicators of Performance Issues
    1. Benchmarking
      1. Microbenchmarks
      2. Java Microbenchmark Harness (JMH)
        1. Benchmark modes
        2. Benchmark time units
        3. Benchmark state
          1. State scope
        4. Fixture methods
          1. Levels of fixture methods
        5. Writing good benchmarks
          1. The pitfalls of loops
          2. Dead Code Elimination
          3. Using black holes
          4. Constant folding
        6. Kotlin benchmarks
        7. IDEA JMH plugin
    2. General performance metrics
      1. Types of performance testing 
      2. Performance testing process
      3. Overview of performance testing tools
        1. JMeter
        2. Fabric
    3. Summary
  8. Learning How to Use Profiling Tools
    1. Memory profiling
      1. Memory Viewer
      2. HProf
      3. Eclipse Memory Analyzer Tool
        1. Histogram
        2. Shallow and Retained Heap
        3. Dominator Tree
        4. Top Consumers
        5. Analyzing class loaders
      4. Android Studio Memory Profiler
        1. Memory categories
        2. Recording memory allocation
    2. Threads profiling
      1. Threads viewer
        1. Frames pane
        2. The Threads pane
      2. Thread profiling in the MAT
        1. Threads Overview
        2. Thread Details
      3. CPU Profiler in Android Studio
        1. Call Chart and Flame Chart tabs
        2. Top Down and Bottom Up tabs
    3. Summary
  9. Functional Approach
    1. Functional programming
      1. Declarative versus imperative
      2. Pure functions
      3. First-class functions
      4. Higher-order functions
      5. Function composition
      6. Lambdas
      7. Closures
      8. Typeclasses
        1. Arrow library
        2. Functor
        3. Monad
      9. Immutability
    2. Inspecting functional features
      1. Inline versus non-inline
      2. Capturing and non-capturing lambdas
    3. Summary
  10. Enhancing the Performance of Collections
    1. Data structures
      1. Arrays
      2. Linked lists
      3. Stacks
      4. Queues
      5. Sets
      6. Maps
      7. Hash tables
      8. Binary search trees
      9. Tries
      10. Binary heaps
      11. Graphs
    2. Time complexity
      1. Calculating time complexity
      2. Time complexity of lists
      3. Time complexity of sets
      4. Time complexity of queues
      5. Time complexity of maps
    3. Collections in Kotlin
    4. Sequences in Kotlin
    5. Summary
  11. Optimizing Access to Properties
    1. Fields and properties
      1. Backing fields
      2. Backing properties
      3. @JvmField annotation
    2. Properties inspection
      1. Compile-time constants
      2. Inner classes
      3. lateinit
      4. Companion objects
    3. Summary
  12. Preventing Unnecessary Overhead Using Delegates
    1. Types of delegation
      1. Explicit delegation
      2. Implicit delegation
    2. Class delegation
    3. Delegated properties
      1. Lazy
      2. Creating a delegated property
      3. Inspecting the lazy function
      4. Observable delegates
    4. Summary
  13. Ranges and Identifying Performance Issues
    1. Ranges in Kotlin
      1. Utility functions
    2. Range benchmarking
    3. Summary
  14. Multithreading and Reactive Programming
    1. Concurrency and parallelism
    2. Reactive programming
    3. Coroutines
      1. Setting up a project
      2. The launch function
      3. The async function
      4. The buildSequence function
      5. The suspendingSequence function
      6. The produce function
      7. Coroutines with reactive programming
    4. Summary
  15. Best Practices
    1. The disposable pattern
    2. Immutability
      1. Data classes
    3. The String pool
      1. StringBuilder
    4. Functional programming
      1. Declarative versus imperative
      2. Pure functions
      3. First-class functions
      4. Higher-order functions
        1. Inline functions
      5. Function composition
      6. Capturing lambdas
    5. Collections
    6. Properties
      1. Backing properties
      2. @JvmField annotation
      3. Top-level members
        1. Compile-time constants
      4. The lateinit modifier
    7. Delegation
      1. Singleton delegate object
      2. The lazy funcation with unsafe thread mode
      3. Delegate object with generic
    8. Ranges
    9. Concurrency and parallelism
    10. Summary
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Mastering High Performance with Kotlin
  • Author(s): Igor Kucherenko
  • Release date: June 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788996648