Skip to content

[Go] Fix to not allocate to the heap when iterating over repeating groups … #994

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

Merged

Conversation

adam-talos
Copy link
Contributor

@adam-talos adam-talos commented May 6, 2024

…in golang 1.22

Verify by running

go build -gcflags=all=-d=loopvar=2

When compiling in Golang 1.22, the loop behavior has changed and the code generated by SBE in Go can suddenly allocate to the heap.

You can verify this by running

go build -gcflags=all=-d=loopvar=2

Before the generated could would look like

	for _, prop := range m.Entries {
		if err := prop.Encode(_m, _w); err != nil {
			return err
		}
	}

This reference to prop could potentially allocate if prop.Encode could not be inlined.

The new code that is generated uses the index to get the reference, which will not allocate.

	for i := range m.Entries {
		if err := m.Entries[i].Encode(_m, _w); err != nil {
			return err
		}
	}

…in golang 1.22

Verify by running
```golang
go build -gcflags=all=-d=loopvar=2
```
@adam-talos adam-talos changed the title Fix to not allocate to the heap when iterating over repeating groups … [Go] Fix to not allocate to the heap when iterating over repeating groups … May 13, 2024
@vyazelenko vyazelenko merged commit e4dd872 into aeron-io:master Jun 18, 2024
DarrylGamroth pushed a commit to New-Earth-Lab/simple-binary-encoding that referenced this pull request Nov 19, 2024
…in golang 1.22 (aeron-io#994)

Verify by running
```golang
go build -gcflags=all=-d=loopvar=2
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants