Can immutable value objects be pulled?

Olexandr Rotan rotanolexandr842 at gmail.com
Sat Jun 8 20:16:58 UTC 2024


Hi! I am writing to express some thoughts that have been crossing my mind
pretty often recently. So basically, what I am wondering is can value
objects be pooled, just like Strings are pooled now?

My thoughts originated from the question of pooling value records and
records in general Value objects seem like ideal candidates to be pooled:
they don't have identity, so there are no things like two different value
objects with the same state but not "completely" equal. Things like
optionals tend to often repeat values, as well as some things that records
are used for such as DTOs and other plain data carriers.

The thing that kind of doubts me is that usual records also are a good
candidate for pooling, but, AFAIK, they aren't for some reason, so I am
wondering maybe this idea has been considered previously but discarded for
some reason like inacceptable performance overhead associated with pooling
mechanism.

But still, widening mechanism that used for String pooling currently I`m
not familiar with exact implementation of String pooling and I suspect it
somehow tied to inlining string literals and that's why it doesn't work for
any other way to create string, so it seems like adapting it to any
constructor will require significant change in pooling mechanism, but it
seems like it potentially could save up ton of memory. I'm not sure about
the performance side of this though.

This letter is more of a question as I am not familiar with string pooling
internals at all, but it seems like a natural thing to me.So, has this been
considered?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20240608/d47a726f/attachment.htm>


More information about the valhalla-dev mailing list