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

*: use generic to improve btree performance #35492

Merged
merged 5 commits into from Jul 15, 2022

Conversation

hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Jun 18, 2022

Signed-off-by: Weizhen Wang wangweizhen@pingcap.com

What problem does this PR solve?

Issue Number: close #34248

Problem Summary:

What is changed and how it works?

package tables

import (
	"fmt"
	"testing"

	"github.com/google/btree"
)

func BenchmarkBtree(b *testing.B) {
	bt := btree.New(32)
	for i := 0; i < 64; i++ {
		bt.ReplaceOrInsert(newBtreeListColumnSearchItem(fmt.Sprintf("%d", i)))
	}
	locations := make([]ListPartitionLocation, 0, bt.Len())

	lo := bt.Min()
	hi := bt.Max()

	b.ResetTimer()
	for j := 0; j < b.N; j++ {
		locations = locations[0:]
		bt.AscendRange(lo, hi, func(item btree.Item) bool {
			locations = append(locations, item.(*btreeListColumnItem).location)
			return true
		})
	}
}

func BenchmarkBtreeG(b *testing.B) {
	bt := btree.NewG(32, lessBtreeListColumnItem)
	for i := 0; i < 64; i++ {
		bt.ReplaceOrInsert(newBtreeListColumnSearchItem(fmt.Sprintf("%d", i)))
	}
	locations := make([]ListPartitionLocation, 0, bt.Len())

	lo, _ := bt.Min()
	hi, _ := bt.Max()

	b.ResetTimer()
	for j := 0; j < b.N; j++ {
		locations = locations[0:]
		bt.AscendRange(lo, hi, func(item *btreeListColumnItem) bool {
			locations = append(locations, item.location)
			return true
		})
	}
}
[xhe@ZEN tables]$ go test  -test.run=^$ -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/pingcap/tidb/table/tables
cpu: AMD Ryzen 7 6800U with Radeon Graphics         
BenchmarkBtree-16         256267              4231 ns/op            7882 B/op          0 allocs/op
BenchmarkBtreeG-16        247459              4195 ns/op            8162 B/op          0 allocs/op
PASS
ok      github.com/pingcap/tidb/table/tables    3.148s
[xhe@ZEN tables]$ go test  -test.run=^$ -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/pingcap/tidb/table/tables
cpu: AMD Ryzen 7 6800U with Radeon Graphics         
BenchmarkBtree-16         238915              4198 ns/op            8454 B/op          0 allocs/op
BenchmarkBtreeG-16        263731              3941 ns/op            7659 B/op          0 allocs/op
PASS
ok      github.com/pingcap/tidb/table/tables    3.014s
[xhe@ZEN tables]$ go test  -test.run=^$ -bench=. -benchmem
goos: linux
goarch: amd64
pkg: github.com/pingcap/tidb/table/tables
cpu: AMD Ryzen 7 6800U with Radeon Graphics         
BenchmarkBtree-16         253676              3943 ns/op            7962 B/op          0 allocs/op
BenchmarkBtreeG-16        281829              4119 ns/op            8960 B/op          0 allocs/op
PASS
ok      github.com/pingcap/tidb/table/tables    3.221s

Check List

Tests

  • Unit test

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jun 18, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • ngaut
  • xhebox

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.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 18, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Jun 18, 2022

@hawkingrei
Copy link
Member Author

/run-check_dev

@ti-chi-bot ti-chi-bot added status/LGT1 Indicates that a PR has LGTM 1. and removed do-not-merge/needs-linked-issue labels Jun 19, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 20, 2022
@xhebox
Copy link
Contributor

xhebox commented Jun 20, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 88cc1a12a0480203559f3619e7b548d6fc488ca0

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 20, 2022
@hawkingrei
Copy link
Member Author

/hold

it meets the bug from the linter. so we wait for bug fixed.

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 20, 2022
@@ -677,7 +681,7 @@ func (lp *ForListPruning) buildListColumnsPruner(ctx sessionctx.Context, tblInfo
ExprCol: columns[idx],
valueTp: &colInfo.FieldType,
valueMap: make(map[string]ListPartitionLocation),
sorted: btree.New(btreeDegree),
sorted: btree.NewG[*btreeListColumnItem](btreeDegree, lessBtreeListColumnItem),
Copy link
Contributor

@xhebox xhebox Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My linter told me that type argument [*btreeListColumnItem] is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the go1.18, Many linter has problems when dealing with generic.

@hawkingrei
Copy link
Member Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 20, 2022
@xhebox
Copy link
Contributor

xhebox commented Jun 21, 2022

/hold

@hawkingrei check_dev

[2022-06-21T02:12:54.424Z] unconvert check(skip check the generated or copied code in lightning)

[2022-06-21T02:16:16.216Z] 2022/06/21 10:16:10 Unexpected package creation during export data loading

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 21, 2022
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed status/can-merge Indicates a PR has been approved by a committer. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 5, 2022
@hawkingrei
Copy link
Member Author

/hold

@hawkingrei
Copy link
Member Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 5a8e80f022fcce9efb632d08aeb5a9f086a84114

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 5, 2022
@hawkingrei hawkingrei removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 5, 2022
@hawkingrei
Copy link
Member Author

/run-all-tests

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Jul 5, 2022
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 15, 2022
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@hawkingrei
Copy link
Member Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 9569565

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 15, 2022
@hawkingrei
Copy link
Member Author

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2022
@hawkingrei
Copy link
Member Author

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2022
@ti-chi-bot ti-chi-bot merged commit db03c0c into pingcap:master Jul 15, 2022
@hawkingrei hawkingrei deleted the update_btree branch July 15, 2022 10:10
@sre-bot
Copy link
Contributor

sre-bot commented Jul 15, 2022

TiDB MergeCI notify

✅ Well Done! New fixed [1] after this pr merged.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/tics-test 🔴 failed 1, success 0, total 1 52 sec Existing failure
idc-jenkins-ci/integration-cdc-test ✅ all 36 tests passed 27 min Fixed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 11 tests passed 22 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 13 min Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 6 min 25 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 30 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 4 min 23 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 2 min 51 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 41 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace google/btree with tidwall/btree to improve performance
5 participants