on main help sign in
perf: reduce lock contention
f1117afRaphael Amorim
internal/llm/prompt/prompt.go+14−10
@@ -79,17 +79,19 @@ func processContextPaths(workDir string, paths []string) string {
79 }
79 }
80 if !d.IsDir() {
80 if !d.IsDir() {
81 // Check if we've already processed this file (case-insensitive)
81 // Check if we've already processed this file (case-insensitive)
82− processedMutex.Lock()
83 lowerPath := strings.ToLower(path)
82 lowerPath := strings.ToLower(path)
83+
84+ processedMutex.Lock()
84− if !processedFiles[lowerPath] {
85+ alreadyProcessed := processedFiles[lowerPath]
86+ if !alreadyProcessed {
85 processedFiles[lowerPath] = true
87 processedFiles[lowerPath] = true
88+ }
86− processedMutex.Unlock()
89+ processedMutex.Unlock()
87
90
91+ if !alreadyProcessed {
88 if result := processFile(path); result != "" {
92 if result := processFile(path); result != "" {
89 resultCh <- result
93 resultCh <- result
90 }
94 }
91− } else {
92− processedMutex.Unlock()
93 }
95 }
94 }
96 }
95 return nil
97 return nil
@@ -98,18 +100,20 @@ func processContextPaths(workDir string, paths []string) string {
98 fullPath := filepath.Join(workDir, p)
100 fullPath := filepath.Join(workDir, p)
99
101
100 // Check if we've already processed this file (case-insensitive)
102 // Check if we've already processed this file (case-insensitive)
101− processedMutex.Lock()
102 lowerPath := strings.ToLower(fullPath)
103 lowerPath := strings.ToLower(fullPath)
104+
105+ processedMutex.Lock()
103− if !processedFiles[lowerPath] {
106+ alreadyProcessed := processedFiles[lowerPath]
107+ if !alreadyProcessed {
104 processedFiles[lowerPath] = true
108 processedFiles[lowerPath] = true
109+ }
105− processedMutex.Unlock()
110+ processedMutex.Unlock()
106
111
112+ if !alreadyProcessed {
107 result := processFile(fullPath)
113 result := processFile(fullPath)
108 if result != "" {
114 if result != "" {
109 resultCh <- result
115 resultCh <- result
110 }
116 }
111− } else {
112− processedMutex.Unlock()
113 }
117 }
114 }
118 }
115 }(path)
119 }(path)