zeroshade commented on PR #645:
URL: https://github.com/apache/arrow-go/pull/645#issuecomment-3780059786

   > I find it a bit tricky with iter.Seq[Field]. By itself it does not 
allocate anything. But calling yield on each iteration effectively allocates a 
record on the heap because 1/ this fails escape test (a record is passed to 
another function and can be used after the current closure returns) and 2/ the 
record has pointers inside. Using iter.Seq[Field] will not allocate a slice, 
but it will allocate the same amount of records on the heap anyway.
   
   I'm confused here, why would yield allocate an entire record on the heap as 
opposed to just creating a copy of the `Field` on the stack? For clarify, I'm 
suggesting using the `slices` package so the function would be like:
   
   ```go
   func (s *Schema) FieldIter() iter.Seq[Field] {
       return slices.Values(s.fields)
   }
   ```
   
   and would then be used like:
   
   ```go
   for f := range sc.FieldIter() {
       // do stuff with f
   }
   ```
   
   So I'm curious what your code path is like such that this would result in 
allocating the entire record on the heap? At worst it would allocate the Schema 
object on the heap? Unless I'm missing something?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to