2024-11-19 19:15:58 +01:00
# Bring Powersort to Java
2024-12-31 14:21:14 +00:00
Implementation of Powersort with the aim of integrating it into OpenJDK. Benchmarks are used to ensure that the runtime of the new sorting algorithm is never slower than the current Timsort implementation.
2024-11-19 19:15:58 +01:00
2025-01-01 18:00:44 +00:00
<!-- TOC -->
* [Bring Powersort to Java ](#bring-powersort-to-java )
* [Setup ](#setup )
* [Development Setup with nix ](#development-setup-with-nix )
* [Tasks ](#tasks )
* [Test Cases ](#test-cases )
* [Benchmark ](#benchmark )
2025-01-07 17:32:18 +00:00
* [Custom ](#custom )
* [JMH ](#jmh )
2025-01-09 11:53:05 +00:00
* [Run JMH with CGL and Powersort competition lists ](#run-jmh-with-cgl-and-powersort-competition-lists )
* [IntelliJ plugin ](#intellij-plugin )
* [Further notes ](#further-notes )
2025-01-01 18:00:44 +00:00
<!-- TOC -->
2024-12-31 14:21:14 +00:00
## Setup
2024-11-19 19:15:58 +01:00
2024-12-31 14:21:14 +00:00
We use Gradle for dependency and build management.
2024-11-23 18:01:53 +01:00
**Commandline**
Check which Java toolchains Gradle finds:
2024-11-19 19:15:58 +01:00
```shell
./gradlew javaToolchains
```
2024-11-23 18:01:53 +01:00
This should include version >= 23, e.g.:
2024-11-19 19:15:58 +01:00
```
+ N/A JDK 23-ga
| Location: /nix/store/48290hnlb13xmwjw9y16a1s785993bv7-openjdk-23-ga/lib/openjdk
| Language Version: 23
| Vendor: N/A
| Architecture: amd64
| Is JDK: true
| Detected by: Current JVM
```
2024-12-31 14:21:14 +00:00
### Development Setup with nix
2025-01-07 17:54:06 +00:00
The provided [./shell.nix ](./shell.nix ) file can be used to set up a development environment with IntelliJ. The only prerequisite is to have a working `nix` installation for which there are multiple possibilities, e.g:
2024-12-31 14:21:14 +00:00
```shell
# https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#determinate-nix-installer
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | \
sh -s -- install
```
Then the dependencies (JDK23, Gradle, IntelliJ) can be installed with:
```shell
nix-shell
```
2024-11-23 18:01:53 +01:00
**IntelliJ**
2024-12-30 16:49:40 +00:00
When using `nix-shell` , some manual configuration is necessary:
2024-11-23 18:01:53 +01:00
2024-12-31 14:21:14 +00:00
- `STRG` `ALT` `SHIFT` `s` -> SDK -> add JDK ->
- home path: `/usr/lib/openjdk`
- name: `usr-lib-jdk`
- `STRG` `ALT` `s` -> build tools -> gradle ->
- local installation: `/usr/lib/gradle`
- Gradle JVM: `usr-lib-jdk`
2024-11-23 18:01:53 +01:00
2024-12-31 14:21:14 +00:00
## Tasks
2024-11-19 19:15:58 +01:00
2024-11-19 19:24:56 +01:00
List all Gradle tasks which can be run:
2024-11-19 19:15:58 +01:00
```shell
./gradlew tasks
```
2024-11-19 19:24:56 +01:00
This can also be done graphically in IntelliJ:
![intellij-gradle.png ](intellij-gradle.png )
2024-12-31 14:21:14 +00:00
## Test Cases
2024-11-19 19:15:58 +01:00
Run the task "test":
```shell
./gradlew test
```
2024-12-30 16:49:40 +00:00
2024-12-31 14:21:14 +00:00
## Benchmark
2024-12-30 16:49:40 +00:00
There are two different benchmarks. One is based on the JMH benchmark framework, the other one is a custom benchmark implementation.
2025-01-07 17:32:18 +00:00
### Custom
2025-01-07 17:54:06 +00:00
Run Custom Benchmark (CGM) with
- Custom Generated Lists (CGL):
2025-01-07 17:32:18 +00:00
```shell
./gradlew runCbmCgl
2025-01-07 17:54:06 +00:00
```
- Powersort competition lists:
```shell
2025-01-07 17:32:18 +00:00
./gradlew runCbmCompetition
```
### JMH
2025-01-07 17:54:06 +00:00
#### Run JMH with CGL and Powersort competition lists
2025-01-07 17:32:18 +00:00
2024-12-30 16:49:40 +00:00
```shell
./gradlew jmh
```
2025-01-07 17:32:18 +00:00
2025-01-07 17:54:06 +00:00
- To benchmark only one of the different list collections, see `jmh { excludes }` at the bottom of [./app/build.gradle.kts ](./app/build.gradle.kts ).
#### IntelliJ plugin
2025-01-07 17:32:18 +00:00
The [JMH Java Microbenchmark Harness ](https://plugins.jetbrains.com/plugin/7529-jmh-java-microbenchmark-harness ) plugin allows running benchmarks from within the IDE in a similar way as JUnit test cases. This can be used for development but yields less accurate results.
2025-01-07 17:54:06 +00:00
![intellij-jmh.png ](intellij-jmh.png )
#### Further notes
2025-01-07 17:32:18 +00:00
- JHM: https://github.com/openjdk/jmh?tab=readme-ov-file#other -build-systems
- We use the JMH Gradle plugin: https://github.com/melix/jmh-gradle-plugin
- Sample JMH Gradle project: https://github.com/twoVersatile/jmhsample