-
Notifications
You must be signed in to change notification settings - Fork 359
feat: use rc to avoid allocating a new string for extension_id #615
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
Conversation
@@ -221,6 +222,7 @@ where | |||
|
|||
let extension_id = register(client, self.extension_name, self.events).await?; | |||
let extension_id = extension_id.to_str()?; | |||
let extension_id_rc = Rc::new(String::from(extension_id)); |
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.
isn't String::from(&str)
an allocation anyways? can we make the extension_id
field an &str
?
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.
- yes you're right but it's done only once (outside the loop) instead of doing it for every received events
- I tried to make it a
&str
but this introduces a lot of lifetime-related code, was a bit less readable (IMHO) and also introduces a breaking change that's why I went with theRc<String>
path
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.
what do you think @greenwoodcm?
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.
ok i think that seems reasonable. is this change non-breaking?
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.
no it's not, I put a warning in the description but this basically modifies the public extension_id
field in LambdaEvent
from String
to Rc<String>
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.
does it make sense to you @greenwoodcm ?
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 extension id is a random string assigned to an extension when it's registered by the runtime to accompany a function. Every time the extension is registered, it receives a new random id.
When I added that field to the event, I thought it could be useful at some point. After further thinking, I don't believe it's really useful for anything worth exposing externally, it should just be an internal implementation detail.
Since this is going to be a breaking change anyways, I'd be more in favor of removing it completely.
Issue #, if available: potential fix for #614
Description of changes:
Using a RC around the extension id.
Now it clones the RC for each event which is way lighter than cloning the full extension_id string
By submitting this pull request