-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Remove unnecessary string conversions in error message construction #5826
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
Remove unnecessary string conversions in error message construction #5826
Conversation
WalkthroughThis change removes unnecessary string conversions (such as Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ExceptionConstructor
Note over Caller,ExceptionConstructor: Previous flow
Caller->>ExceptionConstructor: new_type_error("msg".to_owned())
Note over Caller,ExceptionConstructor: New flow
Caller->>ExceptionConstructor: new_type_error("msg")
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (11)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
vm/src/vm/vm_new.rs
Outdated
pub fn new_exception_msg( | ||
&self, | ||
exc_type: PyTypeRef, | ||
msg: impl Into<String>, | ||
) -> PyBaseExceptionRef { | ||
self.new_exception(exc_type, vec![self.ctx.new_str(msg.into()).into()]) |
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 couldn't find the issue but we once discussed about this changes. We needed a cut to to reduce binary size. I think most of new_*_error is simple wrappers of this function. Then reverting only this one and new_exception_msg_dict
to using String will be good enough keep the balance of DX and having a single code to create params for new_exception.
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.
If one of the goals of the project is to reduce the binary size, I think this PR should be closed then.
I'm all for a clean, and better code as long as it's not hurting the goals of the project:)
If you think it's a good compromise then I'll implement your suggestions, but I'm afraid that you don't want to offend me by just closing the PR lol
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 think the most outer wrappers becomes more cleaner by your way. By only turning new_exception_msg
and new_exception_msg_dict
back to take only String, other changes will not affect binary size.
They are small functions, so must be inlined before.
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.
The binary sizes:
target | main | branch | diff |
---|---|---|---|
debug | 226548kb (222M) | 226620kb (222M) | +72kb |
relase | 21836kb (22M) | 21828kb (22M) | -8kb |
This change actually reduces the binary size on the release target? can you please verify that that's also the case on your machine?
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.
Interesting.
Build command: cargo build --release --no-default-features
(because binary size tweaks usually wants less features)
- Before patch: 15196432
- After patch: 15213472
It increased 17kb for me.
I rebased this patch on current main before build. My arch is aarch64-apple-darwin
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.
Oh, I built mine on aarch64-linux-android
with cargo build
(so with the default features).
I can recheck it without the default features, but I don't see the point in that as I assume the majority of RustPython users are not running on an android.
How should I proceed with this PR, if at all?
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 am good with reverting only new_exception_msg and new_exception_msg_dict but keeping anything else as you did.
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.
- Before patch: 15212688
- After patch: 15200016
There are a lot more places where we can remove the call of
.to_owned()
, but this is just a start.Did it here for a couple of files just to show how much code we can remove.
Summary by CodeRabbit
Summary by CodeRabbit