Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Dynamically Sized fields #8

Open
RichardWarburton opened this issue Jan 4, 2013 · 4 comments
Open

Support Dynamically Sized fields #8

RichardWarburton opened this issue Jan 4, 2013 · 4 comments

Comments

@RichardWarburton
Copy link
Owner

String, byte[] etc.

@jond3k
Copy link

jond3k commented Jan 31, 2013

Any idea how to do this with standard java types without call site modification?

@RichardWarburton
Copy link
Owner Author

My initial plan was to support arrays of primitives, and possibly a few important other types like strings.

I haven't got any particularly smart ideas on this front though. I mean its entirely doable to support them via resizing the entire slab and copying memory. That might be fine for some people, but maybe not so much for others. A possible improvement would be to provide an annotation to say always allocate n items for a dynamically sized field, even if it involves wasted space. Over time it might be possible to learn sizing heuristics based upon the tradeoffs between copying and wasted memory.

If you have good suggestions, feel free to comment.

@jond3k
Copy link

jond3k commented Jan 31, 2013

Since we're using Unsafe for optimisations, copying & resizing don't seem like attractive solutions. My slabs are immutable and long-lived so I haven't thought about resizing dynamic fields much, but as for reading them, I've had to write my own string/array operations that typically involve looping each primitive and using Unsafe.getChar, etc.

Clearly that's a mess, so I've recently considered using flyweights that extend CharSequence for strings, but there are likely to be limitations on what I can do with it. I'm not sure what to do for arrays.

Another idea is exposing functions that would normally require new object construction to work properly (e.g. part of slab -> byte array -> new string) but using something like ASM to stub out the object creation and replace any usage of the expected object with methods that use Unsafe on the original data. This is much more advanced. Perhaps a little bit crazy..

@RichardWarburton
Copy link
Owner Author

I guess the key question when you've got your immutable, long lived slabs
is do you know what the string size is? If you're using some kind of
builder, and then only want slab-like properties over an immutable object
after its constructed, then generating that builder without the overheads
is quite easy.

A CharSequence wrapper is something to look into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants