Feasibility of a Span class in java
Red IO
redio.development at gmail.com
Mon Nov 7 19:53:49 UTC 2022
I've never done bytecode generation before. I will definitely look into it.
About CharSequence, of course I thought about it developing the idea. But
CharSequence is (in my opinion) pretty weak when it comes to methods. In my
mind CharSequence should have almost every method string has since they
almost all can be implemented based on the abstract methods charAt and
length. In its current state char sequence is not very useful. Of cause
writing a small helper class that provides all those methods based on
CharSequence is not too difficult. But it's unnecessary and messy. Also the
adoption of CharSequence in favor of string is poor and requires repeatedly
converting to string destroying any chance of potential performance
improvement of another CharSequence implementer.
On Mon, Nov 7, 2022, 20:09 <forax at univ-mlv.fr> wrote:
>
>
> ------------------------------
>
> *From: *"Red IO" <redio.development at gmail.com>
> *To: *"Remi Forax" <forax at univ-mlv.fr>
> *Cc: *"panama-dev" <panama-dev at openjdk.org>
> *Sent: *Monday, November 7, 2022 6:54:42 PM
> *Subject: *Re: Feasibility of a Span class in java
>
> This looks like it has a pretty large overhead when accessing multiple
> values. I think it would be more beneficial to have 1 object which
> represents the whole range like a list. And is able to subdivide like a
> memory segment. It would practically be a user friendly wrapper for memory
> segments. The biggest challenge with an api like this is
> 1. Primitives inability to be efficiently generic and 2. Integration with
> the whole jdk. The first could be solved in in 2 ways: Valhalla delivers
> generics over primitives (still in development) or old school with a ton of
> duplicate code.
> The second problem would be a group effort. To effectively use this kind
> of api it would need integration in strings, buffers, arrays, lists,
> streams and everywhere you might find a continuous block of data. This
> would require it to become an agreed goal to create it. Otherwise the
> effort would be wasted.
>
>
> It should be efficient given that all span objects are value types, and
> only exist on stack, so can be completly unboxed by a Valhalla VM.
> There is a third options if you want to implement specialized generics
> now, use bytecode generation / method handles / Lookup.defineHiddenClass.
>
> Here is an example of how to have the API of a list/map of records but the
> implementation of a record of arrays.
> https://github.com/forax/struct-of-array
>
> The integration with strings and buffers can be done through
> implementations of CharSequence. Arrays and Map can be implemented by
> bytecode generation and for stream too (but that last part will be painful).
>
> Rémi
>
>
> On Mon, Nov 7, 2022, 18:34 Remi Forax <forax at univ-mlv.fr> wrote:
>
>> It's on my TODO list :)
>>
>> You create an interface
>> interface MutableSpan {
>> int value();
>> void value(int value);
>> }
>>
>> and you can map it to any Panama memory because this is implemented as
>> value class with two fields, a memory segment (or whatever the actual name)
>> and an index.
>> Then you need to see a contiguous space of memory as a List of span
>> objects where the value class instances representing the value are created
>> on the fly when asked.
>>
>> Rémi
>>
>> ------------------------------
>>
>> *From: *"Red IO" <redio.development at gmail.com>
>> *To: *"panama-dev" <panama-dev at openjdk.org>
>> *Sent: *Monday, November 7, 2022 5:59:28 PM
>> *Subject: *Feasibility of a Span class in java
>>
>> Following the development and plans for both Panama's memory access api
>> and the required changes provided by Valhalla while looking at c#'s
>> directions for the last few years I was wondering if writing a class that
>> serves as a universal and easy-to-use interface for accessing memory of all
>> sorts of "value based" types inspired by c#' s Span struct would be
>> beneficial for Java. Of course this assumes the completion of the memory
>> api (panama) , the generic unification (Valhalla) and custom value based
>> types (Valhalla). The idea is to speed up array and string manipulation by
>> using short lived slicing objects (Span). I already wrote a poorly
>> implemented slicer for strings and saw incredible performance gains in
>> comon operations like substring and split.
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20221107/ea33ab5f/attachment-0001.htm>
More information about the panama-dev
mailing list