samber / lo

💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
https://pkg.go.dev/github.com/samber/lo
MIT License
18.02k stars 830 forks source link

do not create wait groups for slices with len less than 2 #517

Open Alexfilus opened 3 months ago

Alexfilus commented 3 months ago

Little improvements for parallel package.

shivamrazorpay commented 3 months ago

@Alexfilus why is the improvement helpful ?? Can you give example or any article from where you get the idea to add this change ?

Alexfilus commented 3 months ago

In my project I am using lop.Map for processing data from db. And I don't know how many row I will get. From 0 to 20. And in case of zero row lop.Map is creating unnecessary waitgroup. In case of 1 row lop.Map is creating unnecessary waitgroup and goroutine. It is just useless work and memory allocations.