pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.41k stars 489 forks source link

auth: avoid copy lots of hash object in caching_sha2 implementation #1422

Closed virusdefender closed 2 years ago

virusdefender commented 2 years ago

Improve caching_sha2 speed

What is changed and how it works?

the Sum method in Hash interface will copy the hash object

https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/crypto/sha256/sha256.go;l=207

it will make lots of hash object in the iteration loop for i = 0; i < iterations; i++

goos: darwin
goarch: amd64
pkg: github.com/pingcap/parser/auth
cpu: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
BenchmarkCachingSHA2

# this pr
BenchmarkCachingSHA2-8           703       1748022 ns/op        9737 B/op          6 allocs/op

# master
BenchmarkCachingSHA2-8           375       3178530 ns/op      320674 B/op      10022 allocs/op

Check List

Tests

ti-chi-bot commented 2 years ago

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment. After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review. Reviewer can cancel approval by submitting a request changes review.
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

ti-chi-bot commented 2 years ago

Welcome @virusdefender!

It looks like this is your first PR to pingcap/parser 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/parser. :smiley:

virusdefender commented 2 years ago

/cc @3pointer

ti-chi-bot commented 2 years ago

@virusdefender: GitHub didn't allow me to request PR reviews from the following users: reviewer.

Note that only pingcap members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to [this](https://github.com/pingcap/parser/pull/1422#issuecomment-1175958437): >/cc @reviewer Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
tangenta commented 2 years ago

Hi @virusdefender, thanks for your contribution!

This repo has been moved to https://github.com/pingcap/tidb/tree/master/parser. Could you please file a PR to https://github.com/pingcap/tidb instead?

virusdefender commented 2 years ago

https://github.com/pingcap/tidb/pull/35999