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

otelslog is not reusing the pooled buffer #5879

Closed
pellared opened this issue Jul 9, 2024 · 0 comments · Fixed by #5878
Closed

otelslog is not reusing the pooled buffer #5879

pellared opened this issue Jul 9, 2024 · 0 comments · Fixed by #5878
Assignees
Labels
bridge: slog Related to the slog bridge bug Something isn't working
Milestone

Comments

@pellared
Copy link
Member

pellared commented Jul 9, 2024

I noticed that this

buf.data = buf.data[:0:0]

"kills" the whole optimization gained from usage of sync.Pool because buf.data[:0:0] makes buf.data to never be really reused.

Demo: #5878

At the same time changing to buf.data[:0] does not work because of the recursive nature of the conversion.
We would need to call free() when everything is converted - e.g. between these lines:

h.logger.Emit(ctx, h.convertRecord(record))
return nil

The other idea is to only use the pool for "top level attributes" (only in convertRecord).
However, the Logger.Emit documentation says:

The record may be held by the implementation. Callers should not mutate the record after passed

This would mean that we cannot pool the attributes as it can be held by the implementation.

@pellared pellared added bug Something isn't working bridge: slog Related to the slog bridge labels Jul 9, 2024
pellared added a commit to open-telemetry/opentelemetry-go that referenced this issue Jul 11, 2024
Add comment which is already in `BytesValue`, `SliceValue`, `MapValue`.

Maybe it would help mitigating issues like
open-telemetry/opentelemetry-go-contrib#5879.
@MrAlias MrAlias added this to the v1.29.0 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridge: slog Related to the slog bridge bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants