From 898606ae4c22c9e04d5cbbdc8dfb77ec638deb4f Mon Sep 17 00:00:00 2001 From: congqixia Date: Fri, 21 Feb 2025 21:41:21 +0800 Subject: [PATCH] enhance: [2.5] Avoid stringtoslicebytes copy for BatchPKExists (#40097) Cherry-pick from master pr: #40096 Using unsafe.Slice to convert string to []byte by directly using underlying data could avoid lots of copy and cpu time Signed-off-by: Congqi Xia --- internal/storage/pk_statistics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/storage/pk_statistics.go b/internal/storage/pk_statistics.go index f984583e75..3586a8288d 100644 --- a/internal/storage/pk_statistics.go +++ b/internal/storage/pk_statistics.go @@ -18,6 +18,7 @@ package storage import ( "fmt" + "unsafe" "github.com/cockroachdb/errors" "github.com/samber/lo" @@ -119,7 +120,7 @@ func Locations(pk PrimaryKey, k uint, bfType bloomfilter.BFType) []uint64 { return bloomfilter.Locations(buf, k, bfType) case schemapb.DataType_VarChar: varCharPk := pk.(*VarCharPrimaryKey) - return bloomfilter.Locations([]byte(varCharPk.Value), k, bfType) + return bloomfilter.Locations(unsafe.Slice(unsafe.StringData(varCharPk.Value), len(varCharPk.Value)), k, bfType) default: // TODO:: }