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

feat: Added Reuse and Initialize methods to LinkBuffer #310

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

JHue58
Copy link

@JHue58 JHue58 commented Feb 19, 2024

When used with sharequeue, the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@JHue58 JHue58 requested review from a team as code owners February 19, 2024 13:04
@CLAassistant
Copy link

CLAassistant commented Feb 19, 2024

CLA assistant check
All committers have signed the CLA.

@joway
Copy link
Member

joway commented Feb 20, 2024

the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@Nana-Miko Hi, can you show me your code and how it cause GC pressure?

@JHue58
Copy link
Author

JHue58 commented Feb 20, 2024

the nodes of LinkBuffer are set to nil after Append, which prevents reuse and causes GC pressure.

@Nana-Miko Hi, can you show me your code and how it cause GC pressure?

sure!

queue := mux.NewShardQueue(mux.ShardSize, conn)

	// Simulating pressure environment using for loops
	for {
		var getter mux.WriterGetter = func() (buf Writer, isNil bool) {
			// I can't use sync.Pool to get buf
			// In this func,'var buf = &LinkBuffer{}' will continuously allocate memory
			buf = NewLinkBuffer(128)

			buf.Malloc(128)
			buf.Flush()
			return buf, false
		}
		queue.Add(getter)
	}

In this example, is there any way to reuse LinkBuffer using sync.Pool?

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

Successfully merging this pull request may close these issues.

None yet

3 participants