Skip to content

cmd/compile: utf8.DecodeRune should be fast/slow-path inlineable #31666

@josharian

Description

@josharian

We manually partially inline utf8.DecodeRune in a few places in the tree. For example, in bytes.EqualFold, we have:

		if s[0] < utf8.RuneSelf {
			sr, s = rune(s[0]), s[1:]
		} else {
			r, size := utf8.DecodeRune(s)
			sr, s = r, s[size:]
		}

It'd be nice to rewrite utf8.DecodeRune like this:

func DecodeRune(p []byte) (r rune, size int) {
	if len(p) > 0 && p[0] < RuneSelf {
		return rune(p[0]), 1
	}
	return decodeRuneSlow(p)
}

and then let mid-stack inlining take it from there. (And delete all the manual partial inlining.)

Unfortunately, this has a cost of 89, over the budget of 80.

This is basically just another variant of #17566, but I'm filing it separately since that issue is super noisy.

cc @bradfitz @mvdan @dr2chase

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions