This commit is contained in:
Daniel 2024-10-18 17:19:48 +08:00
parent 5c274f5c79
commit ab072fc81f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"sync" "sync"
@ -86,10 +87,11 @@ func LoadTree(boxID, p string, luteEngine *lute.Lute) (ret *parse.Tree, err erro
func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse.Tree, errs []error) { func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse.Tree, errs []error) {
waitGroup := sync.WaitGroup{} waitGroup := sync.WaitGroup{}
lock := sync.Mutex{} lock := sync.Mutex{}
loaded := map[string]bool{} poolSize := runtime.NumCPU()
if 8 < poolSize {
//start := time.Now() poolSize = 8
p, _ := ants.NewPoolWithFunc(8, func(arg interface{}) { }
p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {
defer waitGroup.Done() defer waitGroup.Done()
i := arg.(int) i := arg.(int)
@ -101,6 +103,7 @@ func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse
errs = append(errs, err) errs = append(errs, err)
lock.Unlock() lock.Unlock()
}) })
loaded := map[string]bool{}
for i := range paths { for i := range paths {
if loaded[boxIDs[i]+paths[i]] { if loaded[boxIDs[i]+paths[i]] {
continue continue
@ -113,7 +116,6 @@ func batchLoadTrees(boxIDs, paths []string, luteEngine *lute.Lute) (ret []*parse
} }
waitGroup.Wait() waitGroup.Wait()
p.Release() p.Release()
//logging.LogInfof("batch load trees [%d] cost [%s]", len(paths), time.Since(start))
return return
} }