Does anyone have good rules of thumb on when it makes sense to use go routines?
I have been using go routines to speed up large loops of 1000s llm queries and they've been working great. Its an obvious usecase as each llm query may take up to 1 minute and most of the time is just waiting for an external server.
But after seeing how well they worked, I thought about their usage for smaller computational tasks and was wondering when it makes sense to use a goroutine and when it would be better to just use for loops?
Is there a way to determine when it is more efficient to use goroutines versus loops, other than just benchmarks/experimentation?
For instance if we were reading and parsing a large text file with long lines of text?
-
We could increment over each line using a traditional for loop.
-
Run a goroutine to parse each line
-
Split the file into x1 segments of size x2 and then have each parse their own section
Currently my intuition tells me that:
1 Would be best for a text file of single words where we do a very simple calculation
2. would be good for VERY long lines of text with a COMPLEX computation for each
3. would be best for medium lines and medium tasks
So I see situations in which these are all options that may be useful.
Does anyone have good rules of thumb on when it makes sense to use go routines or will I just develop this intuition the more I use/experiment with them?