Skip to content

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

Open
@jakebailey

Description

@jakebailey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImplementationIssues describing a semantics-preserving change to the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions