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

reflect: no efficient way to append to, or grow, a slice #44870

Closed
ianlancetaylor opened this issue Mar 8, 2021 · 5 comments
Closed

reflect: no efficient way to append to, or grow, a slice #44870

ianlancetaylor opened this issue Mar 8, 2021 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ianlancetaylor
Copy link
Member

This is based on https://groups.google.com/g/golang-nuts/c/S2gBW3BV4QU/m/mSPh2_FzBgAJ :

The reflect package has no efficient way to append to a slice represented as a reflect.Value. This is available in the reflect2 package: https://pkg.go.dev/github.com/modern-go/reflect2#UnsafeSliceType.Append. The reflect2 package also has a method to grow a slice to a new size: https://pkg.go.dev/github.com/modern-go/reflect2#UnsafeSliceType.Grow.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 8, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Mar 8, 2021
@zigo101
Copy link

zigo101 commented Mar 8, 2021

If there will be something to do here, I think it would be a good chance to make slice grow implementation in reflection and non-reflection consistent: #41239 (comment)

@robpike
Copy link
Contributor

robpike commented Mar 9, 2021

What is "efficient"? It's possible to grow a slice with the reflect package using more primitive mechanisms. Is it worth providing a special case for that operation? How does one decide what reflect should optimize for?

@martisch
Copy link
Contributor

martisch commented Mar 9, 2021

Previous discussion about Append allocating a new slice header (in addition to potentially a new backing array) always and generally making reflect allocate less: #32424 (comment)

@ianlancetaylor
Copy link
Member Author

Sorry, I got confused here. I think the reflect package is fine.

@advancedwebdeveloper
Copy link

CC @funny-falcon

@golang golang locked and limited conversation to collaborators Mar 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants