Kotlin 2.5.0 is out. The headline is that Kotlin/Wasm went Stable, but for someone writing Kotlin Multiplatform the real news is full value classes: multiple properties, immutable, no generated copy or componentN.

I compiled them on this machine. Three conclusions up front:

  • It is subtraction, not addition. Same fields, five fewer methods, 21% less bytecode than a data class
  • At call sites it is still an object. Nothing gets erased, so boxing and the null check stay
  • It did not get faster. Over 20M points, the value class ran 4.6% slower than the data class, and 21.6% slower than a flat array

How the experiment was set up

Kotlin 2.5.0 command line compiler, JDK 21.0.13.1, one file holding three equivalent types, all compiled in the same unit.

Same data, three declarations

Full value classes need a flag. Without it the compiler refuses, in these exact words:

the feature “full value classes” is experimental and should be enabled explicitly. This can be done by supplying the compiler argument ‘-Xfull-value-classes’

The other flag is -Xvalhalla-value-classes, which compiles Kotlin value classes into JVM value classes. The announcement states it needs JDK 28 or later, for both compilation and execution. This machine runs JDK 21, so that path is untested in this article.

The bytecode is genuinely smaller

javap -p on both classes: identical fields, two doubles each. The difference is the methods.

11 methods vs 6

The data class carries component1, component2, copy, copy$default. The value class has none of them. What disappears is not just four methods but the bytecode behind them: 2188 B against 1729 B, a 459 B gap.

That is by design. An instance is fully determined by its primary properties, so the compiler generates no copy and no positional componentN. It generates equals, hashCode, toString and nothing else of that family.

What pays for the saving is a hard constraint: a value class cannot have a field outside its primary constructor. Want a length? It has to be a getter recomputed on every access, as in the official example val length get() = Math.sqrt(x*x, y*y). No storage, no constructor parameter, and no role in equality.

So what got removed is less the features than the escape hatch that lets an object quietly carry extra state. A data class allows you to add a var beside the constructor, and the moment you do, an instance is no longer uniquely determined by its primary properties.

At call sites, inline and full are two different things

This is the part I think matters most. Both are called value classes, and they behave completely differently in a method signature.

inline is erased, full stays an object

The two inline functions lose the type entirely: useInline-lc-6ta0(String), the parameter is a bare String. Even the nullable version useInlineNullable-oNwqeZs(String) is a String, with null meaning absence and no boxing.

The full value class gets useFull(FullPoint), a real object reference. Inside it calls checkNotNullParameter first, then reads fields through virtual calls. Four instructions in the disassembly: aload_0, invokevirtual getX, invokevirtual getY, dadd.

The inline nullable version is three: aload_0, ifnonnull, aconst_null. No object anywhere in between.

Across the whole MainKt, box-impl appears exactly once, on the listOf(id) line. Boxing did not disappear; it was deferred to the moment a value must become an Object.

Which moments those are: entering any generic container, being used as Any, being stored in a field, being locked by synchronized, being reached by reflection. The first is the one you hit daily, and a single List<InlineUserId> puts every element back into an object.

So “zero overhead value classes” needs a qualifier: zero overhead on the stack and in parameter positions. Once a container is involved they cost the same as ordinary objects.

The benchmark: a tie, leaning slow

Bytecode alone is not enough, so I wrote a crude measurement: 20 million points, the same s += x + y, only the memory layout changes, 7 rounds per group taking the median, three independent runs.

Three layouts, three timings

Median per run: 13.5 / 13.6 / 13.6 ms (data class), 14.3 / 14.2 / 14.2 ms (value class), 10.7 / 10.7 / 10.7 ms (flat DoubleArray).

The value class is 4.6% slower than the data class and 25% slower than the flat array. I will not spin that 4.6% into “value classes are slower”: on an array of objects it is noise. The number that means something is 21.6%, and that is the cost of boxing.

Which is to say: on JDK 21 a full value class buys you API constraints, not performance. The performance column waits for Valhalla, and Valhalla waits for JDK 28.

A caveat on the measurement itself: this is not JMH. No fork isolation, no control over GC. It measures the relative gap between three layouts on one machine, not absolute throughput. The order of magnitude is the claim, not the decimals.

Two syntax boundaries I hit

The first: @JvmInline with two properties is rejected outright.

error: @JvmInline value class must have exactly one primary constructor parameter.

The second is more interesting. The announcement says inline value classes become multiplatform under a unified inline modifier starting in 2.5.20. So what happens in 2.5.0 if you write inline value class R(val x: Double, val y: Double)?

I tried it: it compiles, and quietly becomes a full value class. The R.class it produced has fields, a constructor and getters, and no box-impl or constructor-impl, identical to what value class produces. Not a single warning.

Anyone who reads that as “inline now supports multiple properties” will be caught out when 2.5.20 changes the behaviour. On 2.5.0, keep inline and value separate and do not mix them.

The next few releases are already queued

The announcement lays out the roadmap plainly: 2.5.20 brings better diagnostics for identity, equality and capture, and moves inline value classes to the common inline modifier on all platforms. More ergonomic update syntax, effectively a better copy, is expected in 2.6.0.

Name-based destructuring is already the default in 2.5.0: value classes destructure by property name instead of position. I did not find a trap there, but if you write val (a, b) = p out of habit, note that reordering the properties no longer breaks silently while mismatched names do.

Is it worth using today

If your goal is multi-field immutable values with less boilerplate, value classes work now. The price is an experimental flag, and Alpha means no compatibility promises.

If your goal is performance, two waits apply: on the JVM, JDK 28 plus Valhalla; across platforms, 2.5.20 for the unified inline.

If you only want an API that refuses a bare Double, an inline value class is already enough, and it is more thoroughly erased at call sites than a full one.

One line

What 2.5.0 delivered is not faster value classes. It is value classes that can hold more than one field. Performance was left to a future JVM.

The whole project is still on this machine: compiled output, javap dumps, and the raw numbers from all three runs. If you want to try it in your own code, remember the two flags affect both compilation and execution. Do not let CI and your laptop run different JDKs.

Is your JDK at 28 yet? If your environment already runs -Xvalhalla-value-classes, send me the numbers and this article’s performance section can be finished.