]> Cypherpunks repositories - gostls13.git/commit
go/token: slight performance improvement for IsIdentifier
authorchanxuehong <chanxuehong@gmail.com>
Mon, 21 Feb 2022 08:51:05 +0000 (08:51 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 2 Mar 2022 11:28:40 +0000 (11:28 +0000)
commitbebe9aa42322f951fc3972c263648297bf9e04d4
tree658e3742ed9c6cb4e654f0fadaec96953cbdd5b3
parent9f1239b90a7a48c5dc68a7eee08d8e1fba56db80
go/token: slight performance improvement for IsIdentifier

If name is empty or a keyword, we can skip the loop entirely.
Otherwise, we do the same amount of work as before.

Here is the benchmark result for go/parser:

name          old time/op    new time/op    delta
Parse-12        2.53ms ± 2%    2.47ms ± 1%  -2.38%  (p=0.000 n=9+10)
ParseOnly-12    1.97ms ± 1%    1.93ms ± 2%  -1.80%  (p=0.000 n=10+10)
Resolve-12       560µs ± 1%     558µs ± 1%    ~     (p=0.200 n=9+8)

name          old speed      new speed      delta
Parse-12      26.1MB/s ± 2%  26.8MB/s ± 1%  +2.44%  (p=0.000 n=9+10)
ParseOnly-12  33.6MB/s ± 1%  34.3MB/s ± 2%  +1.82%  (p=0.000 n=10+10)
Resolve-12     118MB/s ± 2%   119MB/s ± 1%    ~     (p=0.116 n=10+8)

Change-Id: I87ac9c2637a6c0e697382b74245ac88ef523bba7
GitHub-Last-Rev: 036bc38d837c095dd5a8d97ece83e1596d875d3e
GitHub-Pull-Request: golang/go#48534
Reviewed-on: https://go-review.googlesource.com/c/go/+/351389
Trust: David Chase <drchase@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/token/token.go