If String was a value class, the JVM could potentially implement small string optimization (SSO), which could completely avoid heap (or stack) allocation for small strings. All three C++ std lib implementations, Boost and Folly do it, so I guess (hope) they measured the performance gains. I don't know how much sense it would make on the JVM though.
On Wed, 2 Sept 2026 at 16:24, Chen Liang <[email protected]> wrote: > > To store the value of a string, you need your storage location (declaration > site) to fit the values. There's no single storage location configuration > that is suitable for all or even many places that need to store the value of > the string directly. Even Databases need you to declare the length of your > VARCHAR explicitly. It's unrealistic for the platform library to model each > used VARCHAR length as a standalone value class of string. This problem does > not exist for 2d points because you know there are two numbers, and each > number is an integer. > > ________________________________ > From: John Bossons <[email protected]> > Sent: Tuesday, September 1, 2026 5:24 PM > To: Chen Liang <[email protected]> > Cc: valhalla-dev <[email protected]> > Subject: Re: [External] : Is it true that String can't become a value class? > And if so, why not? > > The potential gain is the ability to store a string value, rather than a > reference to a string. Same as the ability store a 2Dpoint as a value > containing two numbers, rather than as a reference to the instance. On Tue, > Sep 1, 2026 at 5: 20 PM > > The potential gain is the ability to store a string value, rather than a > reference to a string. Same as the ability store a 2Dpoint as a value > containing two numbers, rather than as a reference to the instance. >
