title: CodeIgniter performance issues with large form
body: <p>I am using CodeIgniter and I have some performance issues with a very large form. Basically it can reach 1,000 fields because it's used for data entry (many of the fields have the same value so the user spends less than 30min filling it thanks to client-side code).</p>
  
  <p>It takes less than a second to show the form populated from the DB. But when the user clicks on submit, the exact same code that now takes the POST data instead of DB data takes forever and usually times out. It works fine for a few hundred fields (taking less than 15s to submit/insert in DB) but if the number of fields is doubled it suddenly takes much, much longer.</p>
  
  <p>There are 3 parts in the code (which I won't copy here because it's very long and complex due to all the logic involved in so many fields):</p>
  
  <ol>
  <li>Prepare the data (from DB or form) inside objects</li>
  <li>Form validation using <code>$this-&gt;form_validation-&gt;run()</code></li>
  <li>DB inserts/edits</li>
  </ol>
  
  <p>Part 1 is very fast when the data is read from the DB for an edit. When the data comes from POST, it never reaches part 2 so it's definitely not an issue with form validation or DB inserts.</p>
  
  <p>As I sometimes get this message, I think the issue comes from the XSS protection from Codeigniter:</p>
  
  <pre><code>Maximum execution time of 90 seconds exceeded in (...)/system/core/Security.php
  </code></pre>
  
  <p>Do you know if using any of these is a bit slow? <code>$this-&gt;post-&gt;input('fieldname', TRUE)</code> and <code>$this-&gt;input-&gt;post(NULL, TRUE)</code>. Does Codeigniter do a lot of calculations each time I use them and should I therefore save each post input into a variable before using them in calculations?</p>
  
  <p>Alternatively I could turn off XSS protection since it's in our admin part but I'd really not go that way.</p>
  
  <p>Or maybe it's not that at all and my code is somehow poor?</p>