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, runtime: optimize comparison of large values with zero #23929

Open
josharian opened this Issue Feb 19, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@josharian
Contributor

josharian commented Feb 19, 2018

package p

type T [20]byte

func f(x *T) bool {
	return *x == T{}
}

Currently this sets up and zeros twenty bytes and then calls memequal. Comparing a large type to zero should be easy; we can then dispatch instead to an optimized runtime routine that doesn't need to actually construct a zero value. (Should handle != as well.)

cc @randall77 @martisch

@josharian josharian added this to the Unplanned milestone Feb 19, 2018

@martisch

This comment has been minimized.

Member

martisch commented Feb 19, 2018

I would suggest to do small compares inline (up to x bytes, like compares, not sure where the cutoff is currently) and when bigger we can call a special runtime routine isZero(*p, len) or alike as suggested.

@cznic

This comment has been minimized.

Contributor

cznic commented Feb 20, 2018

Why aren't non-scalar required zero values ready made in the text segment?

@josharian

This comment has been minimized.

Contributor

josharian commented Feb 20, 2018

And for that matter, why not use runtime.zeroVal?

isZero will still be more efficient, though.

@martisch

This comment has been minimized.

Member

martisch commented Feb 20, 2018

zeroVal can be used up to 1024 bytes.
I think after that if used in maps we allocate bigger zero values.

However flushing multiple cache lines and loading them with zeros for a zero compare seems wasteful and slow if the zero value is not already loaded.

@josharian

This comment has been minimized.

Contributor

josharian commented Feb 20, 2018

Filed #23948 for using runtime.zeroVal.

@randall77

This comment has been minimized.

Contributor

randall77 commented Mar 15, 2018

See #24416 for large struct optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment