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

Optimize allocation in AppendRecordAttrsToAttrs #18

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

lzap
Copy link
Contributor

@lzap lzap commented Dec 17, 2024

SSIA, not sure if you will like it this repo smells with functional programming and I am not sure if this fits the bill :-)

Whatever, cheers!

@@ -17,7 +17,8 @@ import (
type ReplaceAttrFn = func(groups []string, a slog.Attr) slog.Attr

func AppendRecordAttrsToAttrs(attrs []slog.Attr, groups []string, record *slog.Record) []slog.Attr {
output := slices.Clone(attrs)
output := make([]slog.Attr, 0, len(attrs)+record.NumAttrs())
output = append(output, attrs...)
Copy link
Contributor Author

@lzap lzap Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess one could create a new helper in your lo library of functions like CloneAllocate or something :-)

Now that I think about it copy is probably better here.

@samber
Copy link
Owner

samber commented Dec 18, 2024

I appreciate your suggestion.

I have identified other optimizations to make in the project.

Log processing can be costly if coded badly.

@samber samber merged commit e6fb89c into samber:main Dec 18, 2024
1 check passed
@lzap lzap deleted the patch-1 branch January 2, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants