|
13 | 13 |
|
14 | 14 | // The maxParallelTasks is the maximum number of parallel tasks.
|
15 | 15 | maxParallelTasks = runtime.NumCPU() * 3
|
| 16 | + |
| 17 | + // The minLoadPerGoroutine is the minimum slice size for processing |
| 18 | + // in an individual goroutine. Essentially, it delineates the threshold |
| 19 | + // at which it becomes worthwhile to divide the slice processing amongst |
| 20 | + // multiple goroutines. If each goroutine isn't handling a sufficiently |
| 21 | + // large subslice, the overhead of goroutine creation and management |
| 22 | + // may outweigh the benefits of concurrent processing. This variable |
| 23 | + // specifies the minimum number of iterations per goroutine to ensure |
| 24 | + // an efficient division of labor. |
| 25 | + minLoadPeGoroutine = 1024 |
16 | 26 | )
|
17 | 27 |
|
18 | 28 | // Logicable is a special data type from which to determine the state of Trit
|
@@ -215,11 +225,11 @@ func All[T Logicable](t ...T) Trit {
|
215 | 225 | found := &logicFoundValue{value: True}
|
216 | 226 |
|
217 | 227 | // If the length of the slice is less than or equal to
|
218 |
| - // the number of parallel tasks, then we do not need |
| 228 | + // the minLoadPeGoroutine, then we do not need |
219 | 229 | // to use goroutines.
|
220 | 230 | if l := len(t); l == 0 {
|
221 | 231 | return False
|
222 |
| - } else if l < p*2 { |
| 232 | + } else if l/p < minLoadPeGoroutine { |
223 | 233 | for _, v := range t {
|
224 | 234 | trit := logicToTrit(v)
|
225 | 235 | if trit.IsFalse() || trit.IsUnknown() {
|
@@ -283,11 +293,11 @@ func Any[T Logicable](t ...T) Trit {
|
283 | 293 | found := &logicFoundValue{value: False}
|
284 | 294 |
|
285 | 295 | // If the length of the slice is less than or equal to
|
286 |
| - // the number of parallel tasks, then we do not need |
| 296 | + // the minLoadPeGoroutine, then we do not need |
287 | 297 | // to use goroutines.
|
288 | 298 | if l := len(t); l == 0 {
|
289 | 299 | return False
|
290 |
| - } else if l < p*2 { |
| 300 | + } else if l/p < minLoadPeGoroutine { |
291 | 301 | for _, v := range t {
|
292 | 302 | trit := logicToTrit(v)
|
293 | 303 | if trit.IsTrue() {
|
@@ -529,11 +539,11 @@ func Known[T Logicable](ts ...T) Trit {
|
529 | 539 | found := &logicFoundValue{value: True}
|
530 | 540 |
|
531 | 541 | // If the length of the slice is less than or equal to
|
532 |
| - // the number of parallel tasks, then we do not need |
| 542 | + // the minLoadPeGoroutine, then we do not need |
533 | 543 | // to use goroutines.
|
534 | 544 | if l := len(ts); l == 0 {
|
535 | 545 | return False
|
536 |
| - } else if l < p*2 { |
| 546 | + } else if l/p < minLoadPeGoroutine { |
537 | 547 | for _, t := range ts {
|
538 | 548 | trit := logicToTrit(t)
|
539 | 549 | if trit == Unknown {
|
|
0 commit comments