From bdcc9624341ee34298be74a706b09f12f8306456 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期四, 18 四月 2024 23:16:56 +0800 Subject: [PATCH] 优化缓存的数据, 取消多次的base64计算和float32转换 --- cache/shardmap/shardmap.go | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cache/shardmap/shardmap.go b/cache/shardmap/shardmap.go index 255f0c4..daf5f85 100644 --- a/cache/shardmap/shardmap.go +++ b/cache/shardmap/shardmap.go @@ -29,7 +29,7 @@ var Count = make(chan int) -type wfOp func(a []byte, b string) float32 +type wfOp func(a, b []float32) float32 /** * @param uint8, shardCnt must be pow of two @@ -90,7 +90,7 @@ value interface{} } -func (s *ShardMap) Walk(wf wfOp, sourceFea []byte, baseScore float32) (targets []*protomsg.SdkCompareEach) { +func (s *ShardMap) Walk(wf wfOp, sourceFea []float32, baseScore float32) (targets []*protomsg.SdkCompareEach) { var wg sync.WaitGroup var lock sync.Mutex for _, si := range s.shards { @@ -102,18 +102,18 @@ wg.Add(1) - go func(st *shardItem, fw wfOp, sf []byte, baseSec float32) { + go func(st *shardItem, fn wfOp, srcFeat []float32, baseSec float32) { defer wg.Done() for _, feature := range st.data { - if eif, ok := feature.(*db.FeatureCacheBase); ok { + if item, ok := feature.(*db.FeatureCacheBase); ok { score := float32(0) - score = fw(sf, eif.FaceFeature) + score = fn(srcFeat, item.FaceFeature) if score > 0 && score >= baseScore { lock.Lock() targets = append(targets, &protomsg.SdkCompareEach{ - Id: eif.Id, + Id: item.Id, CompareScore: score, - Tableid: eif.TableId, + Tableid: item.TableId, }) lock.Unlock() } -- Gitblit v1.8.0