Skip to content

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

@ppd324

Description

@ppd324

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions