I am new to Golang.
Should I always avoid appending slices?
I need to load a linebreak-separated data file in memory. With performance in mind, should I count lines, then load all the data in a predefined length array, or can I just append lines to a slice?
You should stop thinking about performance and start measuring what the actual bottleneck of you application is.
Any advice to a question like "Should do/avoid X because of performance?" is useless in 50% of the cases and counterproductive in 25%.
There are a few really general advices like "do not needlessly generate garbage" but your question cannot be answered as this depends a lot on the size of your file:
[]string slice 4 times (or 0 times you you make([]string,0,100) it initially). A string is just 2 words.You see: A general advice for performance is a bad advice so I won't give one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With