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

Small optimizations to base64decode #319

Merged
merged 2 commits into from
Aug 9, 2022

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Aug 9, 2022

At an airport so just looking for small stuff :)

  • Don't copy input string to bytes since indexing by number indexes bytes
  • Use strings.Builder, which doesn't copy to output string

Thank you for contributing to Coraza WAF, your effort is greatly appreciated
Before submitting check if what you want to add to coraza list meets quality standards before sending pull request. Thanks!

Note: that go.mod and go.sum can only be modified for tested dependency updates or justified new features.

Make sure that you've checked the boxes below before you submit PR:

Thanks for your PR ❤️

After

goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/transformations
BenchmarkB64Decode
BenchmarkB64Decode/VGVzdENhc2U=
BenchmarkB64Decode/VGVzdENhc2U=-10         	16657209	        68.79 ns/op
BenchmarkB64Decode/P.HNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==
BenchmarkB64Decode/P.HNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==-10         	183049256	         6.552 ns/op
BenchmarkB64Decode/VGVzdABDYXNl
BenchmarkB64Decode/VGVzdABDYXNl-10                                  	17273186	        68.68 ns/op
PASS

Before

goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/transformations
BenchmarkB64Decode
BenchmarkB64Decode/VGVzdENhc2U=
BenchmarkB64Decode/VGVzdENhc2U=-10         	14609536	        79.49 ns/op
BenchmarkB64Decode/P.HNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==
BenchmarkB64Decode/P.HNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==-10         	32041297	        37.65 ns/op
BenchmarkB64Decode/VGVzdABDYXNl
BenchmarkB64Decode/VGVzdABDYXNl-10                                  	15384277	        76.53 ns/op
PASS

@jptosso jptosso merged commit 4bc9ac3 into corazawaf:v3/dev Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants