Two weeks ago, I shared a tip on the one time echo versus print made a difference.
In the article, I had a code example demonstrating the difference, and Joseph Silber drew my attention to the fact that I was calling toString
on a CSV object inside the stream download callback.
As he rightly pointed out, this would in fact load the whole CSV into memory before streaming it. Why is that a problem?
Well, consider an extreme example. Let's say the CSV was 10GB in size. Obviously, trying to load that entire file into memory would run into memory constraints, and even if it worked, it would be very slow compared to streaming it to the user.
He has a great post which goes much, much deeper on this topic if you're interested. I highly recommend it.
In our application, memory consumption was not an issue. These files were small.
All the same, I value being as accurate as possible, and while the tip is still useful, I wanted to offer this additional context to clear up any potential confusion.
Here to help,
Joel
P.S. I actually love it when someone (politely) points out something like this. It's a great way to learn and improve. Keep those replies coming!