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

chunk: reduce chunk's iterator function call #7585

Merged
merged 3 commits into from
Sep 3, 2018

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Reduce chunk's iterator function call.

What is changed and how it works?

Add numRows int to Iterator4Chunk.

Below is a benchmark

func BenchmarkIterator4Chunk_Next(b *testing.B) {
        // 1024 rows
	chk := getChks()
	it := NewIterator4Chunk(chk)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		for row := it.Begin(); row != it.End(); row = it.Next() {
			_ = row
		}
	}
}

old:

BenchmarkIterator4Chunk_Next     2000000              2712 ns/op
BenchmarkIterator4Chunk_Next     2000000              2711 ns/op
BenchmarkIterator4Chunk_Next     2000000              2704 ns/op

this branch

BenchmarkIterator4Chunk_Next     3000000              1412 ns/op
BenchmarkIterator4Chunk_Next     3000000              1411 ns/op
BenchmarkIterator4Chunk_Next     3000000              1410 ns/op

@crazycs520 crazycs520 added sig/execution SIG execution type/enhancement The issue or PR belongs to an enhancement. labels Sep 3, 2018
Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

}

// Begin implements the Iterator interface.
func (it *Iterator4Chunk) Begin() Row {
if it.chk.NumRows() == 0 {
it.numRows = it.chk.NumRows()
if it.numRows == 0 {
Copy link
Contributor

@eurekaka eurekaka Sep 3, 2018

Choose a reason for hiding this comment

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

Is there any use case that we are iterating the chunk while appending into it simultaneously? I guess this is not allowed, just to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

No, there isn't.

}

// Begin implements the Iterator interface.
func (it *Iterator4Chunk) Begin() Row {
if it.chk.NumRows() == 0 {
it.numRows = it.chk.NumRows()
if it.numRows == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

No, there isn't.

chk *Chunk
cursor int
chk *Chunk
cursor int
Copy link
Member

Choose a reason for hiding this comment

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

Can we change the type from int to int32 to make Iterator4Chunk only take 16 bytes in a 64-bit machine?

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added the status/LGT2 Indicates that a PR has LGTM 2. label Sep 3, 2018
@crazycs520
Copy link
Contributor Author

/run-all-tests

@zz-jason zz-jason merged commit e04f74b into pingcap:master Sep 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants