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

Document interned string location #75

Open
Caellian opened this issue Nov 19, 2024 · 3 comments
Open

Document interned string location #75

Caellian opened this issue Nov 19, 2024 · 3 comments

Comments

@Caellian
Copy link

Documentation doesn't specify whether interned string will be moved.

I'm using StringInterner at the moment, but this clarification would be useful for all implementations.

I want to produce Cow<'inerner_owner, str> from strings and am wondering whether inserting new strings can cause their layout to shift.

Example:

  • ["a", ..., "hello", "there", "world"], insert "hello world"
  • ["a", ..., "hello world", "there"]

I'm assuming this isn't the case, but a backend that's optimized for minimal memory footprint could implement such optimizations, so it would be nice for docs to specify whether string position is persistent.

@Robbepop
Copy link
Owner

Hi, this is a good question and indeed we are missing docs for this. From what I remember this use case is exactly what the BucketBackend has been designed for.

@Caellian Caellian changed the title Question: Interned string location Document interned string location Nov 19, 2024
@Caellian
Copy link
Author

Caellian commented Nov 19, 2024

I'm repurposing this question into a task to:

  • Note in documentation that: "returned symbols are stable across insertion, but resolved string references might become invalid for some implementations"
  • Note whether resolved strings are stable in comparison table.

I'll do this shortly in a related PR.

@Caellian
Copy link
Author

Caellian commented Nov 19, 2024

While responding I realized that besides documentation, this can be communicated with lifetimes as well.

#76 would allow constructing Cow<'i, str> via Cow::Borrowed(StringInterner::resolve) directly.

I also realized that StringInterner can't be used to construct Cow<'i, str> that are valid between insertions because an insertion might cause buffer: String to move if it can't grow in place.

Currently, none of the backends support this kind of use and #76 is basically the prerequisite.

I want something along the lines of string_cache (global static cache; refcounted freeing; double/triple indirection), but with more explicit control over when the cache is freed of values (i.e. no global mutex).

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

2 participants