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

cmd/compile: initialize structures more efficiently #18375

Closed
randall77 opened this issue Dec 19, 2016 · 1 comment
Closed

cmd/compile: initialize structures more efficiently #18375

randall77 opened this issue Dec 19, 2016 · 1 comment

Comments

@randall77
Copy link
Contributor

type T struct { a, b, c int } func f(t *T) { *t = T{3,4,5} }
We currently generate a copy from a statictmp to initialize *t. We should instead generate the equivalent of t.a=3;t.b=4;t.c=5.

We should certainly do this for structs that are small and contain no pointers. How large we should go and whether it would be worth it to do so for structs with pointers is TBD. (Possible rule - do this for <= 1 pointer structures.)

See also issue #18370

@mdempsky

@randall77 randall77 added this to the Go1.9 milestone Dec 19, 2016
@josharian
Copy link
Contributor

This appears to have been a dup of #18872. In any case, this was fixed by CL 43154.

"".f STEXT nosplit size=29 args=0x8 locals=0x0
	0x0000 00000 (x.go:5)	TEXT	"".f(SB), NOSPLIT, $0-8
	0x0000 00000 (x.go:5)	FUNCDATA	$0, gclocals·a36216b97439c93dafebe03e7f0808b5(SB)
	0x0000 00000 (x.go:5)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x0000 00000 (x.go:5)	MOVQ	"".t+8(SP), AX
	0x0005 00005 (x.go:5)	MOVQ	$3, (AX)
	0x000c 00012 (x.go:5)	MOVQ	$4, 8(AX)
	0x0014 00020 (x.go:5)	MOVQ	$5, 16(AX)
	0x001c 00028 (x.go:5)	RET

@golang golang locked and limited conversation to collaborators May 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants