Skip to content
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

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Aug 9, 2024

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?

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo requested a review from silver-ymz as a code owner August 9, 2024 11:27
@Xuanwo Xuanwo merged commit dac28d1 into main Aug 9, 2024
258 checks passed
@Xuanwo Xuanwo deleted the try-use-log-kv branch August 9, 2024 12:22
Comment on lines +198 to +204
context.iter().enumerate().map(|(i, (k, v))| {
if i > 0 {
format!(" {}={}", k, v)
} else {
format!("{}={}", k, v)
}
}).collect::<String>()
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants