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

proposal: image: NewDecoder that reuses previously allocated Image #71417

Closed
ppd324 opened this issue Jan 24, 2025 · 1 comment
Closed

proposal: image: NewDecoder that reuses previously allocated Image #71417

ppd324 opened this issue Jan 24, 2025 · 1 comment

Comments

@ppd324
Copy link

ppd324 commented Jan 24, 2025

Proposal Details

In a high-concurrency environment and the image file is large, image.Decode will consume a lot of memory. Is it possible to provide a similar like json package NewDecoder function to write the decoded image to an external image object? User code can use sync.Pool to reuse the image object.

var imagePool = sync.Pool{
	New: func() any {
		return image.NewNRGBA(image.Rect(0, 0, 0, 0))
	},
}

img := imagePool.Get().(*image.NRGBA)
image.NewDecoder(img).Decode(imageReader)

Image

@gopherbot gopherbot added this to the Proposal milestone Jan 24, 2025
@seankhliao seankhliao changed the title proposal: image: image.Decode consumes a lot of memory proposal: image: NewDecoder that reuses previously allocated Image Jan 24, 2025
@seankhliao
Copy link
Member

Duplicate of #8055

@seankhliao seankhliao marked this as a duplicate of #8055 Jan 24, 2025
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants