Temptations of B3
Dimitris Paltatzidis
dcrystalmails at gmail.com
Sun Apr 30 19:41:39 UTC 2023
Very happy with the Valhalla direction. The design could be reaching global
bedrock, if not there already.
Just the devil's advocate.
Without loss of generality, let's take the familiar with Valhalla,
rational number, and model it with a class. We're faced with a few choices:
1. Value class? Yes.
2. Implicit initialization? No, we can't have a zero denominator.
3. Non-atomicity? No, cause 2. is no.
So we can conclude that Rational is a plain value class and no more (or
less should I say).
Now, let's do the same with a complex number:
1. Value class? Yes.
2. Implicit initialization? Yes, the zero is valid.
3. Non-atomicity? Yes, no cross-field invariants.
So, Complex can enjoy everything Valhalla produced. But, why is that? And
here is where the temptations rise.
- From a representation perspective, Rational is a subset of Complex, they
are not that different after all.
- Both will be used in the same context of primitive-like behaviour, with
high performance requirements.
In a perfect world, we would like users to resist those temptations, and
model each class in the bucket it belongs to. But, when people are faced
with the dilemma of (something) vs. performance, they skew towards the
latter, as we've seen with x, y point arrays, object pools, etc...
It might not be far-fetched to encounter B3 Rational's' out there or
whatnot.
The fewer the obstacles that prevent B3 are, the less of a dilemma it
becomes. "Look the other way".
We want the ratio of all value classes:
.filter(shouldn't-B3).filter(modeled-B3) / .filter(shouldn't-B3) to be 0.
But, what that number might actually be? What's an acceptable threshold?
What if it's close to 1?
Of course, preview features will help us here.
Another temptation might rise when non-atomicity is valid but default
initialization is not, as with Rational.
Lastly, a Range class should not be non-atomic, but many might model it as
such, with the mindset of B3 won't make your broken program broken-er.
Unfortunately or not, context matters. Not all Range's' are gonna be used
with the same level of concurrency, back to use-site vs declaration-site...
Even though identity-free classes of any bucket bring
representational power into the model, people might view Valhalla as a
performance marketing term and focus only on that.
This is more or less of an existential crisis: What if everyone jumps to B3?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-comments/attachments/20230430/1c2b5b25/attachment-0001.htm>
More information about the valhalla-spec-comments
mailing list