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

Add sync.Pool to reuse packet conn buf object #56

Merged
merged 1 commit into from
Jan 18, 2023
Merged

Add sync.Pool to reuse packet conn buf object #56

merged 1 commit into from
Jan 18, 2023

Conversation

kz-sher
Copy link

@kz-sher kz-sher commented Jan 18, 2023

What are the changes?

  • Apply sync.Pool to cache packet conn buf object instead of creating one each time.

Why is this useful?

  • This is an optimisation that alleviates the GC pressure by reducing allocation of packet conn buf object.

Other details:

  • There is no need to reset packet conn buf object before putting it back to sync.Pool. This is because we want to reserve the size of buf and the number of bytes will be specified each time.
  • The input parameters of internal goroutine function are unnecessary as those variables are safe and accessible to the namespace shared with the internal goroutine function.

Copy link
Owner

@huin huin left a comment

Choose a reason for hiding this comment

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

Interesting. Out of curiousity, was this causing significant GC pressure as suggested? I hadn't expected this to be used in a scenario where that would happen.

@huin huin merged commit 62bd5c7 into huin:main Jan 18, 2023
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.

None yet

2 participants