Skip to content

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

Open

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.

Activity

  1. added
    ImplementationIssues describing a semantics-preserving change to the Go implementation.
    on May 22, 2025
  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    compiler/runtimeIssues related to the Go compiler and/or runtime.
    on May 24, 2025
  3. added this to the Backlog milestone on May 28, 2025
  4. camdenmcgath commented on Nov 11, 2025

    @camdenmcgath

    @jakebailey Just want to confirm this still needs to be worked on as I'm going to start poking around on some potential fixes

  5. jakebailey commented on Nov 11, 2025

    @jakebailey
    ContributorAuthor

    Yes, I haven't worked on this and have not seen anyone else do so.

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

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions