0
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
..
end

format.csv {send_data(export), :type => 'text/csv;header=present',:filename => 'export.csv') }

I want to export large amounts of data.But it bring a serious performance problems and it filled my memory.Any better ways to export csv?

Peter Brown
  • 50,956
  • 18
  • 113
  • 146

1 Answers1

1

FCSV is the same as FasterCSV, right?

2 suggestions to deal with the memory:

  1. Write the output to a temporary file, then send that. That way you don't need the whole thing in memory
  2. Stream the output directly to the user instead of building it up in memory. For example, see accepted answer to this question: Streaming CSV Download from Rails 3.2 app

If the generation take too much time to execute, then you'll have to profile the code then try to improve it... Alternatively, do the generation as a background task and allow the user to fetch it later.

Community
  • 1
  • 1
Tim Peters
  • 4,034
  • 2
  • 21
  • 27
  • Thank you for your suggestions.This is a good idea.But I successfully exported.The memory still filled – d_shaco May 17 '12 at 07:05