-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Shrink JS-allocated strings down to the correct size before passing them to Rust #3808
Conversation
@@ -1314,6 +1309,7 @@ impl<'a> Context<'a> { | |||
const ret = encodeString(arg, view); | |||
{debug_end} | |||
offset += ret.written; | |||
ptr = realloc(ptr, len, offset, 1) >>> 0; |
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.
Could add a check for whether len != offset
before reallocing again, to avoid spurious allocs.
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.
I considered that, but I didn't think it'd be worth it since in the vast majority of cases the string won't take up the maximum amount of space anyway.
I'd be fine to add it if you want but I don't think the difference would be significant either way.
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.
Would you mind adding a changelog entry as well considering this is an actual user-facing fix?
…hem to Rust Fixes rustwasm#3801. I opted to solve it this way rather than just pass the capacity to Rust as well because it means the allocation isn't up to 3x bigger than it needs to be anymore. I also removed a TODO about fixing that.
f483e15
to
170aba2
Compare
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.
LGTM!
Fixes #3801.
I opted to solve it this way rather than just pass the capacity to Rust as well because it means the allocation isn't up to 3x bigger than it needs to be anymore. I also removed a TODO about fixing that.