Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/base64: NewEncoding not optimized #53211

Closed
ErikPelli opened this issue Jun 2, 2022 · 1 comment
Closed

encoding/base64: NewEncoding not optimized #53211

ErikPelli opened this issue Jun 2, 2022 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance

Comments

@ErikPelli
Copy link
Contributor

ErikPelli commented Jun 2, 2022

In the base64 (and also base32) initialization function, NewEncoding, in the base64.go file, there is a loop that sets decodemap (256 bytes array) to 0xFF.

I found that it can be optimized using the copy() function like a memset.
I will open a Pull Request soon.

ErikPelli added a commit to ErikPelli/go that referenced this issue Jun 2, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function.

Fixes golang#53211
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/410194 mentions this issue: encoding/base64: optimize decodemap memory set

@seankhliao seankhliao added Performance NeedsFix The path to resolution is known, but the work has not been done. labels Jun 3, 2022
ErikPelli added a commit to ErikPelli/go that referenced this issue Jun 3, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied.

BenchmarkDecodeMapInitialize
BenchmarkDecodeMapInitialize/new
BenchmarkDecodeMapInitialize/new-4              1000000000             0.3040 ns/op
BenchmarkDecodeMapInitialize/linear
BenchmarkDecodeMapInitialize/linear-4            7650738               162.7 ns/op

Fixes golang#53211
ErikPelli added a commit to ErikPelli/go that referenced this issue Jun 7, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied.

BenchmarkDecodeMapInitialize
BenchmarkDecodeMapInitialize/new
BenchmarkDecodeMapInitialize/new-4             10321790               115.8 ns/op
BenchmarkDecodeMapInitialize/linear
BenchmarkDecodeMapInitialize/linear-4           5102305                 222.4 ns/op

Fixes golang#53211
ErikPelli added a commit to ErikPelli/go that referenced this issue Jun 8, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied.

BenchmarkNewEncoding
OLD
BenchmarkNewEncoding-4           2689240               395.3 ns/op
NEW
BenchmarkNewEncoding-4           4556568               227.2 ns/op

Fixes golang#53211
ErikPelli added a commit to ErikPelli/go that referenced this issue Jun 12, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied.

name           old time/op    new time/op    delta
NewEncoding-4     329ns ± 1%     231ns ± 1%  -29.72%  (p=0.008 n=5+5)

name           old speed      new speed      delta
NewEncoding-4   778MB/s ± 1%  1108MB/s ± 1%  +42.29%  (p=0.008 n=5+5)

Fixes golang#53211
ErikPelli added a commit to ErikPelli/go that referenced this issue Aug 14, 2022
The existing implementation has an execution time higher in the benchmark than this one.
This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied.

name           old time/op    new time/op    delta
NewEncoding-4     329ns ± 1%     231ns ± 1%  -29.72%  (p=0.008 n=5+5)

name           old speed      new speed      delta
NewEncoding-4   778MB/s ± 1%  1108MB/s ± 1%  +42.29%  (p=0.008 n=5+5)

Fixes golang#53211
@golang golang locked and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants