1st time 500x rendering slowdown #478

Closed
jshow opened this Issue Feb 27, 2012 · 9 comments

Comments

Projects
None yet
3 participants

jshow commented Feb 27, 2012

Hello,

I've been tracking this issue for a few days now.

Some very slow simple_form renders.

From 8ms to as slow as 4000ms.

After reading through the simple_form source, I'm guessing this is because of autoloads. possible ?

The first time a vm renders a simple_form simple_form objects are loaded.

The question I have is about the boot time - I would prefer that the initialization is done earlier, when the container is booting, not when I have user waiting for a page to render. (4 seconds and they're gone).

Also 4 seconds seems huge. Is there some opportunities for speeding up the init ?

thanks for your thoughts.

Owner

josevalim commented Feb 28, 2012

Can you provide a sample app that reproduces this issue? And what simple form, rails and ruby version are you using?

Your reasoning seems to be correct (autoload is being kicked in) but Simple Form on its own should not take 4 seconds. It should not even take a full second. So maybe there are other things at play?

jshow commented Feb 28, 2012

funny, I didn't get an email from your response

ruby 1.9.2p290, rails 3.2.0, simple_form 2.0.1

4 seconds was on the high side - but 3-3.5 was normal.

I've replaced the autoloads with requires, and the behaviour has stopped. I still see gc going on, but the big spikes are gone.

jshow commented Feb 28, 2012

why is it that autoloads are being used ?

it seems to me, that if I'm using simple_form, I have at least one simple_form to render. If the autoloads get triggered for that one form, then our users are being disadvantaged.

I would prefer to load all resources up front, and not slow down the pipeline

I can understand how autoloads can be quite nice for some architectures where components may be loaded or not (for instance rails) - but question whether this benefits gems like this that will definitely be used at some point if installed

Of course this is being over-accentuated by a 4second load peak which is odd in itself

am I off my rocker ?

Owner

josevalim commented Feb 28, 2012

If we load everything up-front, Rails boot time will be slow in development and testing environments. The best solution would be provide an API like SimpleForm.eager_load! that you could use to eager load everything in production.

Anyway, I assume that in your case after the inicial spike of 3-4 seconds, the other requests are fast enough?

jshow commented Feb 28, 2012

correct - after the first load the renders are the expected speed

this is the render speed pattern I see using requires (the occasional 200 feels like gc)
Rendered layouts/_search_header.html.haml (35.1ms)
Rendered layouts/_search_header.html.haml (33.6ms)
Rendered layouts/_search_header.html.haml (9.1ms)
Rendered layouts/_search_header.html.haml (9.7ms)
Rendered layouts/_search_header.html.haml (235.9ms)

thank you joesevalim

jshow commented Feb 28, 2012

fyi, I had to re-order the requires :

  require 'simple_form/components'
  require 'simple_form/error_notification'
  require 'simple_form/map_type'
  require 'simple_form/inputs'
  require 'simple_form/i18n_cache'
  require 'simple_form/helpers'
  require 'simple_form/form_builder'
  require 'simple_form/wrappers'

@ghost ghost assigned josevalim Mar 2, 2012

jshow commented Jan 2, 2013

rafaelfranca does this mean that the issue is (only) addressed for >= rails4

Collaborator

rafaelfranca commented Jan 2, 2013

@jshow yes. This API is not available in Rails < 4

rafaelfranca added a commit that referenced this issue Jan 2, 2013

Collaborator

rafaelfranca commented Jan 28, 2013

@jshow just backported to master, so it will work with 3.x

rafaelfranca added a commit that referenced this issue Jan 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment