Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

mydump,restore: reduce parser memory allocation #108

Merged
merged 3 commits into from
Dec 24, 2018
Merged

Conversation

lonng
Copy link
Contributor

@lonng lonng commented Dec 21, 2018

What problem does this PR solve?

Reduce parser memory allocation

Benchmark (SQL file: 1529669bytes ~1.5MB, Chunk size: 64KB, Rows: 223):

Previous benchmark ref: #107, BenchmarkChunkRestoreReuseBuffer3 is the latest version.

goos: darwin
goarch: amd64
pkg: github.com/pingcap/tidb-lightning/lightning/restore
BenchmarkChunkRestoreReuseBuffer-8           500           2295399 ns/op         7472180 B/op        630 allocs/op
BenchmarkChunkRestoreReuseBuffer2-8         1000           1839265 ns/op         4141669 B/op        444 allocs/op
BenchmarkChunkRestoreReuseBuffer3-8         1000           1644459 ns/op         2499033 B/op        420 allocs/op
PASS

What is changed and how it works?

Add blockBuf to parser

Check List

Tests

  • Unit test
  • Integration test

Code changes

Side effects

Related changes

@sre-bot
Copy link

sre-bot commented Dec 21, 2018

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@lonng
Copy link
Contributor Author

lonng commented Dec 21, 2018

/run-all-tests

@lonng
Copy link
Contributor Author

lonng commented Dec 21, 2018

/run-integration-test

@lonng
Copy link
Contributor Author

lonng commented Dec 21, 2018

/run-all-tests

@lonng
Copy link
Contributor Author

lonng commented Dec 21, 2018

/run-integration-test

@lonng lonng added status/PTAL This PR is ready for review. Add this label back after committing new changes priority/normal type/enhancement Performance improvement or refactoring labels Dec 21, 2018
Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

LGTM

@kennytm kennytm added status/LGT1 One reviewer already commented LGTM (LGTM1) and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Dec 21, 2018
@lonng
Copy link
Contributor Author

lonng commented Dec 22, 2018

@july2993 @GregoryIan PTAL

switch err {
case io.ErrUnexpectedEOF, io.EOF:
parser.isLastChunk = true
fallthrough
case nil:
tryAppendTo(&parser.buf, block[:n])
parser.remainBuf.Reset()
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we omit remainBuf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can not, because of parser.buf reference to appendBuf.Bytes()

Copy link
Collaborator

Choose a reason for hiding this comment

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

leave a comment above code

@IANTHEREAL
Copy link
Collaborator

LGTM

@IANTHEREAL IANTHEREAL added status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) and removed status/LGT1 One reviewer already commented LGTM (LGTM1) labels Dec 24, 2018
@lonng lonng merged commit 2826e79 into master Dec 24, 2018
@lonng lonng deleted the lonng/pr-parser-mem branch December 24, 2018 06:01
@@ -1386,7 +1387,7 @@ func (cr *chunkRestore) restore(

// sql -> kv
start = time.Now()
kvs, _, err := kvEncoder.SQL2KV(buffer.String())
kvs, _, err := kvEncoder.SQL2KV(hack.String(buffer.Bytes()))
Copy link
Member

Choose a reason for hiding this comment

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

We should change the argument type of SQL2KV from string to byte slice. You should not use hack package usually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/LGT2 Two reviewers already commented LGTM, ready for merge (LGTM2) type/enhancement Performance improvement or refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants