]> Cypherpunks repositories - gostls13.git/commit
unicode/utf8: make DecodeRune{,InString} inlineable
authorJulien Cretel <jub0bsinthecloud@gmail.com>
Tue, 2 Sep 2025 22:10:40 +0000 (22:10 +0000)
committert hepudds <thepudds1460@gmail.com>
Wed, 3 Sep 2025 14:04:47 +0000 (07:04 -0700)
commit925a3cdcd13472c8f78d51c9ce99a59e77d46eb4
tree52488ccff88e1b6a81631eb3e086e41b50d1340b
parent3e596d448fb6b9668d144cffaa65e1d12a5fdce8
unicode/utf8: make DecodeRune{,InString} inlineable

This change makes the fast path for ASCII characters inlineable in
DecodeRune and DecodeRuneInString and removes most instances of manual
inlining at call sites.

Here are some benchmark results (no change to allocations):

goos: darwin
goarch: amd64
pkg: unicode/utf8
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
                             │     old      │                 new                  │
                             │    sec/op    │    sec/op     vs base                │
DecodeASCIIRune-8              2.4545n ± 2%   0.6253n ± 2%  -74.52% (p=0.000 n=20)
DecodeJapaneseRune-8            3.988n ± 1%    4.023n ± 1%   +0.86% (p=0.050 n=20)
DecodeASCIIRuneInString-8      2.4675n ± 1%   0.6264n ± 2%  -74.61% (p=0.000 n=20)
DecodeJapaneseRuneInString-8    3.992n ± 1%    4.001n ± 1%        ~ (p=0.625 n=20)
geomean                         3.134n         1.585n       -49.43%

Note: when #61502 gets resolved, DecodeRune and DecodeRuneInString should
be reverted to their idiomatic implementations.

Fixes #31666
Updates #48195

Change-Id: I4be25c4f52417dc28b3a7bd72f1b04018470f39d
GitHub-Last-Rev: 2e352a0045027e059be79cdb60241b5cf35fec71
GitHub-Pull-Request: golang/go#75181
Reviewed-on: https://go-review.googlesource.com/c/go/+/699675
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
14 files changed:
src/bufio/bufio.go
src/bytes/bytes.go
src/bytes/iter.go
src/cmd/compile/internal/test/inl_test.go
src/encoding/json/decode.go
src/fmt/format.go
src/fmt/print.go
src/regexp/regexp.go
src/strconv/quote.go
src/strings/iter.go
src/strings/reader.go
src/strings/strings.go
src/unicode/utf8/utf8.go
src/unicode/utf8/utf8_test.go