u/benrush0705

1 post karma · 91 comment karma · joined Jan 2024

benrush0705

Where is my favourite MemorySegment class?

benrush0705

I personally really like the approach of programming with immutable objects, but after running some benchmarks with JMH, I found that the VM isn’t always able to optimize away object allocations effectively. Once the allocation rate goes up, the JMH results can blow up—the measurement error can easily exceed the actual measured value, and heavy GC involvement makes the real throughput look terrible. So, if an algorithm requires constructing many small objects that share some similarities, I feel that repeatedly resetting and reusing a mutable class is a better choice than using record-like assignments with with-style copying.

That said, I wonder whether Valhalla will improve this situation in the future, or perhaps I'm making some other mistakes. But as things stand, allocation and GC are not free—at least in JMH stress tests, their impact on application performance is quite apparent. I'd really appreciate it if someone more knowledgeable could shed some light on this.

benrush0705

I am very curious about the functionality of abstract records. I can’t think of a good use case for them right now, especially since we can already achieve similar effects by having multiple records implement the same interface. However, I have a guess: is this related to Valhalla? Could it allow value records to enjoy the benefits of value types while also supporting polymorphism? I hope someone with insider knowledge can provide an answer.

benrush0705

I recently tried something similar: parsing strings to integers in Java using this SWAR technique for acceleration. But to my surprise, the JMH benchmarks showed that performance actually got worse, not better — even for long integers, which puzzled me even more. In my implementation, SWAR required assuming the data was valid; if a non‑digit character was encountered, I had to locate its position and re‑parse. Integers usually don't have many digits, and the failure rate when reading 8 or 4 bytes at once wasn't low. I suspect this penalty mechanism caused the performance degradation. In the end, I abandoned the SWAR approach and went back to processing one byte at a time. I'm not familiar with Scala, but I'm very curious how you managed to achieve such good benchmark results.

benrush0705

Can't use annotation processing to register SPI services is a really pain point for me, I have to write a maven plugin for it to work, hopes that someday it could be fixed by the JDK developers! u/pron98

benrush0705

Man! What is Flow? I only see chi on github.

benrush0705

just wait for valhalla,maybe as soon as jdk27 hopefully!

benrush0705

Great article, but at the end there seems to be a mistake: `64-bit native memory pointers, obtained via malloc, are 16-byte aligned`. It seems that this topic has been discussed at https://github.com/openjdk/jdk/pull/28235, the answer should be: it depends.

benrush0705

Great! Remind me when it got fully open sourced!

benrush0705

It seems that there is currently no jep for this, and `witness` needs to be delivered before we saw valhalla get into preview. I really wish it could be faster.

benrush0705

Yeah, that's the plan I am using currently, I guess it's not so elegant so I am just looking for a better approach, let's just wait for Valhalla.

benrush0705

I am curious about using primitive values in StableValue, should I put it in a record wrapper, or Integer would just be fine when valhalla comes?

benrush0705

Early days I saw posts about virtual thread already beat async code at performance, but in this post I saw completely different results, so who is right then?

benrush0705

Would an embeddable, Redis-compatible, Java-based in-memory store be valuable to you?

My answer would be absolutely yes.

benrush0705

Sorry, my bad for just let GPT summarize the jep for me.

benrush0705

u/pron98 After this jep got released, could final fields be trusted by VM just like records? For example, private static record members could be contant folded, but final members couldn't currently, I think it will be much more satisfied if they could be constant folded too.

benrush0705

I think you should just fork it and make the changes on the source code, that's much better than hacking with reflection.

benrush0705

So, value class is not certain to be released in jdk25, sad.

benrush0705

Thanks for your effort, by the way, JSpecify currently only got null marked annotations, which I think would be completely removed when Valhalla came out, so when will JSpecify have its own ValueBased annotation? Also, are you going to follow up this too?

benrush0705

I am curious that, since you are using FFI, why the parameters are still byte[], I thought using MemorySegment for either heap or non-heap would be better.

benrush0705

value classes, with expressions, stable values, string template.

benrush0705

Thanks for your answer, that is very clarified.

benrush0705

Could anyone explain to me that why fields in value class must all be final? I thought it's something like struct in C, so everything should be mutable as well, is it a feature or a must?

benrush0705

Could we see StableValue in jdk24? I noticed it has been submitted.

benrush0705

why is that?