Re: [go-nuts] Dereferencing struct field triggers heap allocation for the complete struct

2024-08-30 Thread rkerno
Thanks Robert, I've come to the same conclusion. I'm guessing the approach simplifies and speeds up the escape analysis, though appears to be a significant limitation. The following extract from escape.go seems to apply. https://tip.golang.org/src/cmd/compile/internal/escape/escape.go // Ever

Re: [go-nuts] Dereferencing struct field triggers heap allocation for the complete struct

2024-08-30 Thread Robert Engels
Yes, but the called function can retain a reference to the string - strings are pointers. it cannot retain a reference to the scalar. I’m guessing if any of the elements can be retained then the entire structure is allocated on the heap - I don’t think it has to but it is probably the current imple

Re: [go-nuts] Dereferencing struct field triggers heap allocation for the complete struct

2024-08-30 Thread rkerno
Thanks Robert. I don't think it's the value that's causing thisI still get the allocation if I remove the value from the equation. It's something to do with the root level having children. The escape analysis from the refactored code below is: go build -gcflags='-m=2' . ./alloc.go:12:27: p

Re: [go-nuts] Concatenate iterators

2024-08-30 Thread costin
Thanks! That looks like a useful package. On Friday, August 30, 2024 at 6:37:01 PM UTC+1 Ian Lance Taylor wrote: > On Fri, Aug 30, 2024 at 10:33 AM costin wrote: > > > > Is there a way to concatenate 2 iterators (other than writing my own > function)? There isn't any std function I could find.

Re: [go-nuts] Concatenate iterators

2024-08-30 Thread Ian Lance Taylor
On Fri, Aug 30, 2024 at 10:33 AM costin wrote: > > Is there a way to concatenate 2 iterators (other than writing my own > function)? There isn't any std function I could find. Would such a function > belong in the iter package (slices seems like the wrong place)? It would probably start out in

[go-nuts] Concatenate iterators

2024-08-30 Thread costin
Is there a way to concatenate 2 iterators (other than writing my own function)? There isn't any std function I could find. Would such a function belong in the iter package (slices seems like the wrong place)? -- You received this message because you are subscribed to the Google Groups "golang-

Re: [go-nuts] Dereferencing struct field triggers heap allocation for the complete struct

2024-08-30 Thread robert engels
because when you only access an int that is passed by value in the function it knows it can’t escape. if you pass the string/value than the the variable can escape, and since the value could point back to the struct itself, it can escape, meaning the entire struct needs to be on the heap. > O

[go-nuts] Dereferencing struct field triggers heap allocation for the complete struct

2024-08-30 Thread rkerno
Hi Everyone, https://gist.github.com/rkerno/c875609bdeb2459582609da36b54bf72 I'm struggling to wrap my head around the root cause of this issue. Accessing certain fields of a struct triggers go to allocate the complete struct on the heap. The key ingredients are: - A struct with a containe

[go-nuts] State Management with Go

2024-08-30 Thread GamiPress Cordial
I want to build an Application like Facebook. Now, I've started using *Svelte* and *SvelteKit*, but I'm noticing quite some level of complexity that wants to kill me. So I thought to ask, "*How can I build a website 100% like Facebook with GO"* ? *React*, *Vue* and *Svelte* shined, and the mai

[go-nuts] Re: Iterator handling error

2024-08-30 Thread Bob Glickstein
I like: ```go func Iter(ctx, data) (iter.Seq[Object], *error) ``` There are some examples of this pattern in https://pkg.go.dev/github.com/bobg/seqs Cheers, - Bob On Thursday, August 29, 2024 at 5:41:47 AM UTC-7 Dmitriy P wrote: > What is the best way to handle errors with iterators? > > How t

[go-nuts] [security] Go 1.23.1 and Go 1.22.7 pre-announcement

2024-08-30 Thread announce
Hello gophers, We plan to issue Go 1.23.1 and Go 1.22.7 during US business hours on Thursday, September 5. These minor releases include PRIVATE security fixes to the standard library and the toolchain, covering the following CVEs: - CVE-2024-34155 - CVE-2024-34156 - CVE-202

[go-nuts] Re: Suppress GoFmt-generated error with/tools.go?

2024-08-30 Thread peterGo
Mike, Let's use official Go sources. go/src/cmd/tools/tools.go: $ go version go version devel go1.24-0f003f9d15 Thu Aug 29 09:15:06 2024 + linux/amd64 $ $ cat tools.go // Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license t

[go-nuts] Re: Iterator handling error

2024-08-30 Thread Christoph Berger
Opinionated answer: If a container type cannot iterate over its elements without fail, I would refrain from trying to build a standard iterator for this container type. You'd be shoehorning an iterator that can fail into the iter API that is not designed for dealing with errors. Putting half-w