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

tablecodec: optimize DecodeRowKey #7149

Merged
merged 1 commit into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tablecodec/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ func BenchmarkEncodeRowKeyWithPrefixNex(b *testing.B) {
sk.PrefixNext()
}
}

func BenchmarkDecodeRowKey(b *testing.B) {
rowKey := EncodeRowKeyWithHandle(100, 100)
for i := 0; i < b.N; i++ {
DecodeRowKey(rowKey)
}
}
9 changes: 4 additions & 5 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ func DecodeTableID(key kv.Key) int64 {

// DecodeRowKey decodes the key and gets the handle.
func DecodeRowKey(key kv.Key) (int64, error) {
_, handle, err := DecodeRecordKey(key)
// errors.Trace can't be inlined by compiler, let's check error explicitly
if err != nil {
return handle, errors.Trace(err)
if len(key) != recordRowKeyLen || !hasTablePrefix(key) || !hasRecordPrefixSep(key[prefixLen-2:]) {
return 0, errInvalidKey.Gen("invalid key - %q", key)
}
return handle, nil
u := binary.BigEndian.Uint64(key[prefixLen:])
return codec.DecodeCmpUintToInt(u), nil
}

// EncodeValue encodes a go value to bytes.
Expand Down