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 larger inline strings #119

Open
ParkMyCar opened this issue Jun 20, 2022 · 6 comments
Open

Support larger inline strings #119

ParkMyCar opened this issue Jun 20, 2022 · 6 comments

Comments

@ParkMyCar
Copy link
Owner

With the recent advancements in const generics, it's theoretically possible to support a CompactString with a user defined size that is > 24, e.g. 32, 40, 48 bytes long. We should try doing this and playing with an API

@CAD97
Copy link
Contributor

CAD97 commented Jun 21, 2022

The way to do so would be to switch Repr (back) to a (*mut (), [MaybeInit<u8>; N], NonMaxU8) layout. However, this N probably wants to be { max(CONFIGURED_INLINE_SIZE, 24) - size_of::<*mut ()>() - size_of::<NonMaxU8>() }, so still requiring const dependent types (which aren't stable yet) or typenum to polyfill.

Typenum supports lifting and lowering to/from plain const generics, so the API can still be pure const generics even if the implementation uses typenum to do math to them.

@Kijewski
Copy link
Contributor

Maybe the other direction would be possible, too? 16 bytes with the capacity on the heap.

@NobodyXu
Copy link
Contributor

Maybe the other direction would be possible, too? 16 bytes with the capacity on the heap.

Nah, I don't think this is a good idea.

That would make CompactString incompatible with String.
Conversion from String or to it would have to take extra time to realloc/rewrite the layout.

It would also impact ToCompactString implementation, which also relies on O(1) conversion from String.

@stepancheg
Copy link

It might be useful to have something like CompactStr type which is 16 bytes and compatible with Box<str>.

@ParkMyCar
Copy link
Owner Author

Coming back to this, my time should be freeing up soon, and I was thinking about how to further improve compact_str. What I think makes the most sense is to work on first is this and #264.

I plan to put together a proposed design/"next steps" soon which will cover additional variants like CompactStr or CompactPath and would love any and all thoughts, I'll update this thread when it's written :)

@NobodyXu
Copy link
Contributor

Coming back to this, my time should be freeing up soon, and I was thinking about how to further improve compact_str. What I think makes the most sense is to work on first is this and #264.

Good to hear, I really want #264 to be done and I thought about implementing it myself, but I am a bit busy recently so not enough time for this.

I plan to put together a proposed design/"next steps" soon which will cover additional variants like CompactStr or CompactPath and would love any and all thoughts, I'll update this thread when it's written :)

For CompactPath, I think it might make sense to first implement unix::CompactOsStr, which can contain arbitrary byte and windows::CompactOsStr, which contains utf-16.

Once they are ready, compact_str can trivially define CompactOsStr and then CompactPath.

Even if it fails, it would still have some usable types for further investigation/experiments.

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

No branches or pull requests

5 participants