Optimize Your Kotlin Performance - Profiling, Micro-optimizations and Precomputing

Опубликовано: 20 Январь 2023
на канале: Pairing with Duncan
1,207
35

In the last episode (   • TDD Algorithm Design - Generating Ana...  ) we had fun generating anagrams. The code was too slow though, so today we are going to look at optimizing the performance of our algorithm.

We start with a performance test to allow us to measure how long it is taking, and then profile the running code in IntelliJ to see where it is spending most of its time. That gives us candidates for micro-optimizations - making specific pieces of code run quicker.

When that stops paying dividends we turn our attention to a more major change - precomputing information so that we we can weed out non-anagrams quicker. This needs structural changes, but gives another speed boost without making everything incomprehensible.

The code is available on GitHub - https://github.com/dmcg/bumper-generator
I'm offering a prize of a signed copy of my book to the best suggestion for further optimization - either raise a PR or, if you just have a bright idea, let's chat about it in the comments below.

If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev