-
Notifications
You must be signed in to change notification settings - Fork 49
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
Intern property and class names, use UstrMap for properties #462
Intern property and class names, use UstrMap for properties #462
Conversation
Revert "Add property name interning" This reverts commit e82c3dbc8dc0269c399d69dbc2a7a9d0d7ff554b.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use Ustr
in rbx_xml for SharedString
and Ref
rewrites. It'll be a small change but I expect it'll add up with Ref
rewrites in particular.
Changes look good to me overall though. Thanks for taking this on.
Any ideas? |
Okay I have an answer not very much time later. Turns out that "being generic over the hasher" is a bit of a misnomer since some of the functionality with hashmaps in the standard library literally isn't. This is for a good reason, but I hate it. If you are curious: the type of HashMap is The consequence is that We may consider exporting a helper trait to implement this stuff for people. It's particularly annoying to lose |
Yeah, it isn't perfect. We should determine the feasibility of these and try contributing some patches upstream to ustr. In the meantime, do you have any ideas for the helper traits? Not too sure what to do there |
We'll need to decide what to do for change logs too, I'd appreciate any input on that |
I'm not sure how feasible it actually is to contribute a patch for this upstream; they'd probably need to just implement the helper traits themselves, which feels like it might be considered bloat since it's technically not necessary. A helper trait I have in mind is something like this: pub trait UstrMapExt {
fn new() -> Self;
fn with_capacity(capacity: usize) -> Self;
}
impl<V> UstrMapExt for UstrMap<V> {
fn new() -> Self {
UstrMap::default()
}
fn with_capacity(capacity: usize) -> Self {
UstrMap::with_capacity_and_hasher(capacity, Default::default())
}
} For I'm not sure what we can do about |
I'm thinking we need to include 3 things in the changelog:
Otherwise, I don't think there's really that much to get into. Everything should work the same, it's just that the public-facing API changed. |
I think we're all ready to go here - if you have no other objections, let's merge, and then I'll be able to submit a few other performance related changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Let's roll.
This PR closes #112 and (partially?) #457 by adding ustr as a dependency, using interned strings for property and class names, and using
UstrMap
for property maps.On my M1 MacBook, this improves rbx_binary's "Serialize 10,000 Parts" and "Deserialize 10,000 Parts" benchmarks by ~46% and ~49%, respectively, and reduces the number of heap allocations by ~84% (but I only profiled allocations when deserializing, maybe allocations during serialization is something a reviewer can check).
This change is breaking because it changes many public method signatures on
InstanceBuilder
, and changes the type ofInstance.properties
(which is public) fromHashMap<String, Variant>
toUstrMap<Variant>
.For convenience, I had rbx_dom_weak re-export some ustr members. Please let me know if these should be more or different!