-
Notifications
You must be signed in to change notification settings - Fork 481
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
refactor(core): Use kv based context to avoid allocations #4986
Conversation
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
context.iter().enumerate().map(|(i, (k, v))| { | ||
if i > 0 { | ||
format!(" {}={}", k, v) | ||
} else { | ||
format!("{}={}", k, v) | ||
} | ||
}).collect::<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.
Looks like we need more allocations than before. One string for each key-value pair and the collected 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.
Perhaps we could use a single string with calculated capacity to ensure only one allocation occurs. Or something better, we can implement a new type LoggingContext(&[(&str, &str)])
and implement Display
for it.
Would you like to help implement it?
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.
A new type should be better. Should we expose this new type to users?
Would you like to help implement it?
Sure.
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.
Should we expose this new type to users?
I'm guessing we don't need to, just wrap it while calling log!()
should be fine.
Which issue does this PR close?
Followup of #4961
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?