golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
120.1k stars 17.24k forks source link

encoding/json: optimize tag parsing by introducing cutTag helper function #67100

Open aimuz opened 2 weeks ago

aimuz commented 2 weeks ago

Refactor tag parsing in json encoding to use a new helper function, cutTag, improving readability and potentially enhancing performance.

goos: darwin goarch: arm64 pkg: encoding/json cpu: Apple M2 Max │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ CodeEncoder-12 330.4µ ± 5% 342.0µ ± 6% ~ (p=0.393 n=10) CodeEncoderError-12 403.9µ ± 8% 342.5µ ± 5% -15.21% (p=0.000 n=10) CodeMarshal-12 429.6µ ± 6% 407.3µ ± 7% -5.17% (p=0.043 n=10) CodeMarshalError-12 486.5µ ± 5% 481.5µ ± 5% ~ (p=0.105 n=10) CodeDecoder-12 1.806m ± 6% 1.783m ± 6% ~ (p=0.247 n=10) CodeUnmarshal-12 2.308m ± 1% 2.269m ± 8% ~ (p=0.315 n=10) CodeUnmarshalReuse-12 1.805m ± 5% 1.791m ± 6% ~ (p=0.739 n=10) geomean 800.0µ 774.0µ -3.25%

                  │   old.txt    │               new.txt                │
                  │     B/s      │     B/s       vs base                │

CodeEncoder-12 5.470Gi ± 5% 5.284Gi ± 6% ~ (p=0.393 n=10) CodeEncoderError-12 4.475Gi ± 7% 5.277Gi ± 4% +17.93% (p=0.000 n=10) CodeMarshal-12 4.207Gi ± 6% 4.437Gi ± 8% +5.47% (p=0.043 n=10) CodeMarshalError-12 3.715Gi ± 5% 3.753Gi ± 5% ~ (p=0.105 n=10) CodeDecoder-12 1.001Gi ± 5% 1.014Gi ± 5% ~ (p=0.247 n=10) CodeUnmarshal-12 801.8Mi ± 1% 815.6Mi ± 8% ~ (p=0.315 n=10) CodeUnmarshalReuse-12 1.001Gi ± 5% 1.009Gi ± 5% ~ (p=0.739 n=10) geomean 2.259Gi 2.335Gi +3.36%

                  │   old.txt    │               new.txt                │
                  │     B/op     │     B/op      vs base                │

CodeEncoder-12 1.000 ± ? 2.000 ± ? ~ (p=0.534 n=10) CodeEncoderError-12 138.0 ± 1% 137.0 ± 1% ~ (p=0.440 n=10) CodeMarshal-12 1.855Mi ± 1% 1.856Mi ± 1% ~ (p=0.853 n=10) CodeMarshalError-12 1.889Mi ± 1% 1.893Mi ± 1% ~ (p=0.631 n=10) CodeDecoder-12 822.1Ki ± 1% 823.8Ki ± 1% ~ (p=0.739 n=10) CodeUnmarshal-12 1.917Mi ± 0% 1.918Mi ± 0% ~ (p=0.064 n=10) CodeUnmarshalReuse-12 711.9Ki ± 0% 712.5Ki ± 0% ~ (p=0.085 n=10) geomean 47.63Ki 52.57Ki +10.38%

                  │    old.txt    │               new.txt                │
                  │   allocs/op   │  allocs/op   vs base                 │

CodeEncoder-12 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ CodeEncoderError-12 4.000 ± 0% 4.000 ± 0% ~ (p=1.000 n=10) ¹ CodeMarshal-12 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=10) ¹ CodeMarshalError-12 6.000 ± 0% 6.000 ± 0% ~ (p=1.000 n=10) ¹ CodeDecoder-12 25.20k ± 0% 25.20k ± 0% ~ (p=0.699 n=10) CodeUnmarshal-12 39.99k ± 0% 39.99k ± 0% ~ (p=1.000 n=10) ¹ CodeUnmarshalReuse-12 25.21k ± 0% 25.22k ± 0% ~ (p=0.093 n=10) geomean ² +0.01% ² ¹ all samples are equal ² summaries must be >0 to compute geomean

gopherbot commented 2 weeks ago

This PR (HEAD: ad9c8645ffa3013a81e947ab74e64da3b9965406) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/582295.

Important tips:

gopherbot commented 2 weeks ago

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Zhen Li:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from qiulaidongfeng:

Patch Set 1: Code-Review+1 Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Go LUCI:

Patch Set 1:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2024-04-29T11:03:29Z","revision":"53fa18743c63077424a8af9aac9e2e78c951dc5d"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Daniel Martí:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from qiulaidongfeng:

Patch Set 1: -Commit-Queue


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Go LUCI:

Patch Set 1:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Go LUCI:

Patch Set 1: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!

gopherbot commented 2 weeks ago

Message from Zhen Li:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/582295. After addressing review feedback, remember to publish your drafts!