Re:Choosing a more optimal `String` type
by cratermoon on Friday September 22, 2023 @07:41PM
(#37619186)
Why use strings and pass them around in the first place? Why not limit the use of String types to system boundaries where data must be serialized into or from character-oriented streams?
Re:Choosing a more optimal `String` type
by amalcon on Friday September 22, 2023 @08:02PM
(#37619327)
The typical strategy for doing that in a context like this is string interning. That's literally what most of the types described in the post are doing behind the scenes, in one form or another. The post is literally about doing your suggestion -- just using a library to do so, and leveraging the type system to reduce some of the boilerplate.
Re:Choosing a more optimal `String` type
by kibwen on Friday September 22, 2023 @08:32PM
(#37619517)
From 1983:
Although "optimum" is an absolute term, like "unique", it became common verbal practice to make it relative: "not quite optimum" or "less optimum" or "not very optimum". Mel called the maximum time-delay locations the "most pessimum".
Re:Choosing a more optimal `String` type
by nmilo on Friday September 22, 2023 @09:15PM
(#37619767)
There should be a from_raw_parts-like interface for Arc that can construct one out of a pointer to a T + control block. That way you can shift the string data over and stick the control block inline (which is how I assume it's laid out in memory) and convert String to Arc<str> for free (well not free, shifting takes O(n), but so does the copying in Arc::new, so in the end you do end up avoiding an allocation for free)
Re:Choosing a more optimal `String` type
by LegionMammal978 on Saturday September 23, 2023 @12:35AM
(#37620603)
Unfortunately, this can't really be done with how allocation works in Rust. A String is always allocated with alignment 1, but an Arc's control block requires usize alignment. An allocated pointer can't be deallocated with a different alignment, nor can its alognment be changed when reallocating. Thus, the from_raw_parts() idea would be unusable for all types with less than usize alignment.
(And the need for atomic operations on the control block precludes the idea of simply letting it be unaligned.)
Re:Choosing a more optimal `String` type
by thfuran on Saturday September 23, 2023 @05:31AM
(#37621798)
Something that is optimal under some set of assumptions and under some specific conditions is likely not optimal under all conditions. Does that mean it's not optimal under any conditions? If not, is something that is optimal under more conditions not "more optimal"?
Although "optimum" is an absolute term, like "unique", it became common verbal practice to make it relative: "not quite optimum" or "less optimum" or "not very optimum". Mel called the maximum time-delay locations the "most pessimum".
https://users.cs.utah.edu/~elb/folklore/mel-annotated/node1....
Verbing weirds language.
https://www.gocomics.com/calvinandhobbes/1993/01/25
See https://github.com/rosetta-rs/string-rosetta-rs for some more analysis. HipStr also has a decent table [1]
[0] https://www.reddit.com/r/rust/comments/117ksvr/ecow_compact_...
[1] https://crates.io/crates/hipstr
(And the need for atomic operations on the control block precludes the idea of simply letting it be unaligned.)
I'll add this to my list of reasons why alignment is terrible.