title: Rendering Performance when populating Nested Form - Rails 4 - OmniContacts
body: <p>In my app I am using the OmniContacts gem to allow users to import their contacts. This works. Getting the contacts for Gmail takes roughly 300-500ms.</p>
  
  <p>In order to allow the importing of the contacts I am putting them in a nested form. Now the rendering of each contact takes 175-300ms, multiply this by 1000 and this are crappy.</p>
  
  <p>I would love there to be a rails solution for this issue. Otherwise I am guessing using AJAX and a JS form might work. Your thoughts and time are appreciated.</p>
  
  <p><strong>Import Controller:</strong></p>
  
  <pre><code>  def import
      @user = current_user
      @import = request.env['omnicontacts.contacts']
      @contacts = @import.map do |contact_info|
        Contact.new(
          first_name: contact_info[:first_name],
          last_name:  contact_info[:last_name],
          email_home: contact_info[:email],
          phone_home: contact_info[:phone]
        )
      end
  
      respond_to do |format|
        format.html
      end
    end
  </code></pre>
  
  <p><strong>Import View:</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="small-12"&gt;
      &lt;%= simple_form_for(@user, url: import_path) do |f| %&gt;
          &lt;%= f.simple_fields_for :contacts, @contacts do |contact| %&gt;
              &lt;%= render 'contact_fields', f: contact %&gt;
          &lt;% end %&gt;
          &lt;div class="actions" align="right"&gt;
            &lt;%= f.submit class:"button tiny" %&gt;
          &lt;/div&gt;
      &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Nested Form Partial:</strong></p>
  
  <pre><code>&lt;div class='nested-fields'&gt;
    &lt;fieldset&gt;
    &lt;div class="row"&gt;
      &lt;div class="small-2 columns"&gt;
        &lt;%= f.input :import, as: :boolean %&gt;
      &lt;/div&gt;
      &lt;div class="small-2 columns"&gt;
        &lt;%= f.input :first_name %&gt;
      &lt;/div&gt;
      &lt;div class="small-2 columns"&gt;
        &lt;%= f.input :last_name %&gt;
      &lt;/div&gt;
      &lt;div class="small-4 columns"&gt;
        &lt;%= f.input :email_home %&gt;
      &lt;/div&gt;
      &lt;div class="small-2 columns"&gt;
        &lt;%= f.input :phone_home %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;/fieldset&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Log of Doom: (close your eyes and imagine 1000+ Rendered lines added)</strong></p>
  
  <pre><code>Started GET "/oauth2callback?code=4/XzHDNPJ8RgRb7SFStQ3tVM-ff2q5WolrVHTsokI0egg" for ::1 at 2015-06-18 12:16:09 -0500
  Processing by ImportsController#import as HTML
    Parameters: {"code"=&gt;"4/XzHDNPJ8RgRb7SFStQ3tVM-ff2q5WolrVHTsokI0egg"}
    User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
    Rendered imports/_contact_fields.html.erb (301.0ms)
    Rendered imports/_contact_fields.html.erb (233.9ms)
    Rendered imports/_contact_fields.html.erb (276.8ms)
    Rendered imports/_contact_fields.html.erb (180.3ms)
    Rendered imports/import.html.erb within layouts/application (1001.0ms)
    Rendered layouts/_header.html.erb (2.8ms)
    Rendered layouts/_footer.html.erb (3.8ms)
  Completed 200 OK in 1548ms (Views: 1540.0ms | ActiveRecord: 0.5ms)
  </code></pre>