good-story
Technologies used
1. Introduction
An investigation and comparison between Kotlin and Java on an engineering level. Since beauty is in the eye of the beholder, this repository is not meant to evaluate Java or Kotlin on an aesthetic level.
This project started as an idea to explore differences in performance between different projects. It has grown now into a full fledge comparison between Java and Kotlin and ONLY for engineering purposes.
I won't dive into style IT discussions in this project. And of course the elegant
card is not the focal point here.
If you understand these terms, then I think you'll find this project interesting.
The way we are going to compare performance, response times and memory usage is going to be by processing a small novel I'm developing in the GoodStory file. We will apply algorithms to it, make objects, and explore the limits of our own machines.
Further, you may find that I'm using for
, while
and a do..while
in both Java
and Kotlin
implementations. This is purposely done in some cases. I may find that in some cases there is no point in using the already implemented algorithm for some situations. Especially if they can be implemented in exactly the same way in Java
or Kotlin
without the use of a DSL.
Lombok
usage will be avoided as much as possible and so please do not be surprised if you get to see any manual implementation of the builder pattern.
1.1. About performance
It caught my attention recently that in many blogs and videos, people are stressing out that coroutines and virtual threads are not about performance. That is of course directly true. What they are about is making a better use of a resource that has been there for ages. Sometimes called Continuation, sometimes called coroutines, but this is a concept that has been here for a long time. This repository is, regardless, about performance, because if we use our resources better, then that will ultimately result in better performance as a whole. So this repo is not about comparing the individual performance of one coroutine to one virtual thread. They work as a whole, both switch context, both can be suspended and both have different states. So I am measuring, or better yet, attempting to measure performance on a local machine and try to see if there is any significant difference there. These tests are also allowing to exhaust resources and therefore forcing each implementation to manage itself. It's here where the performance study comes in.
This repo is the official support repo to my article on medium:
Kotlin Coroutines vs Java Virtual Threads — A good story, but just that…
2. Environment
Java Project Loom is itself a JDK and in order to use it, you need first to install it
check the Makefile for the most appropriate script for your operating system.
make sdk-install
3. Tech comparisons
We cannot 100% compare Kotlin and Java in a direct way, but we will compare them using their best performant version:
Solution | VM Name | VM Version | Base JDK | Type |
---|---|---|---|---|
Kotlin Coroutines | Loom | 19-loom+6-625 (2022/4/29) | 19 | JDK |
Project Loom | Loom | 19-loom+6-625 (2022/4/29) | 19 | JDK |
Please keep checking the evolution of file Log.md if you want to keep up to date with the results of the comparisons. It gets updated per commit. You can also check the detailed file for Java and the detailed file for Kotlin.
4. Actions
This project makes usage of one single action:
5. How top run
You can run the whole test in one go by running:
make clean build-run
For heavier tests please run:
make clean build-run-loccal
Just make sure that loom-jdk is setup in /loom-jdk at the root of this project. Check the sdk scripts in the Makefile for distribution choices for the Loom JDK.
Coffee Sessions
☕️
6.
7. References
Online
- Coroutines are not about multi-threading at all
- Structured concurrency by Roman Elizarov
- libdill: Structured Concurrency for C
- Java Virtual Threads by Gaetano Piazzolla
- Carrier Kernel Thread Pinning of Virtual Threads (Project Loom)
- GitHub's "Our response to the war in Ukraine"
🇺🇦 - Why Continuations are Coming to Java
- Coroutines overview
- JetBrains’ Statement on Ukraine
🇺🇦 - Scala (programming language)
- History of Scala
- Project Loom (Java 19)
- Java (programming language)
☕ - Project Loom: Fibers and Continuations for the Java Virtual Machine
- Coming to Java 19: Virtual threads and platform threads
- STAR method interview
✨ - Amazon Leadership Examples on Youtube
- System Design Messenger on Youtube
- Behavioral Interview Prep
- System - Design - Primer
- Grokking the System Design Interview
- Grokking the Coding Interview: Patterns for Coding Questions
- Big O Notation and Time/Space Complexity
- Analysis of Algorithms | Big-O analysis
- BTech smart class - Introduction to algorithms
- Splay tree
- Big-O Quiz
- Sieve of Eratosthenes
- Binary search tree
- The height of an AVL tree containing n nodes
- AVL Tree
- Data Structure and Algorithms - AVL Trees
- AVL Tree Insertion, Rotation, and Balance Factor Explained
- What is an AVL tree?
🌳 - AVL Tree program in Java
- How to insert Strings into an AVL Tree
- Big O Factorial Time Complexity
- BIG O NOTATION PRIMER
- What would cause an algorithm to have O(log log n) complexity?
- What does O(log n) mean exactly?
- Big O Notation, Part Two: Space Complexity
- ALGORITHMS IN KOTLIN, BIG-O-NOTATION, PART 1/7
- Big O Cheat Sheet
- Time complexity vs. space complexity
- Complexity and Big-O Notation
- Going inside Java’s Project Loom and virtual threads
- Kotlin Coroutines dispatchers
- VisualVM
- Picocli
- Issues with Spring, how Micronaut solves it, and latter’s support for GraalVM
- Kotlin Coroutines
- Java Project Loom
- GitHub Action for GraalVM
- Project Loom: Understand the new Java concurrency model
- Going inside Java’s Project Loom and virtual threads
Videos
Books
- Mcdowell, G. (23rd April 2020). Cracking the Coding Interview 189 Programming Questions and Solutions. (6th Edition). CareerCup
- Cormen, T. Leiserson, C. Rivest, R. Stein, C. (2009). Introduction to Algorithms. (Third Edition). MIT Press