8000 unique: optimize interning of string([]byte) in structs/arrays · Issue #73821 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

unique: optimize interning of string([]byte) in structs/arrays #73821

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

Open
jakebailey opened this issue May 22, 2025 · 1 comment
Open

unique: optimize interning of string([]byte) in structs/arrays #73821

jakebailey opened this issue May 22, 2025 · 1 comment
Labels
Implementation Issues describing a semantics-preserving change to the Go implementation.

Comments

@jakebailey
Copy link
Contributor

Filing this as a continuation of #71926; in CL 672135 I optimized code like:

func BytesToHandle(b []byte) unique.Handle[string] {
	return unique.Make(string(b))
}

This covers probably the bulk of the users, however "composite" cases where strings are inside a struct or array aren't optimized:

func BytesPairToHandle(b1, b2 []byte) unique.Handle[[2]string] {
	return unique.Make([2]string{string(b1), string(b2)})
}

// --- or ---

type Pair struct {
	S1 string
	S2 string
}

func BytesPairToHandle(b1, b2 []byte) unique.Handle[Pair] {
	return unique.Make(Pair{string(b1), string(b2)})
}

This would be good to improve, I just didn't as the corresponding optimization for dictionary keys is within the "order" part of the compiler when it's looking at (roughly) the syntax of a map access and I couldn't quicky come up with the code to do it for the unique.Make calls.

@gabyhelp
Copy link

@gabyhelp gabyhelp added the Implementation Issues describing a semantics-preserving change to the Go implementation. label May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Issues describing a semantics-preserving change to the Go implementation.
Projects
None yet
Development

No branches or pull requests

2 participants
0