My Rails 3.0 app on ruby 1.8.7 contains Haml 3.1.3. Most of the views are haml templates, it takes about 0.5-5ms to render them on my machine in production mode.
Having said that, a few partials take much longer. 300ms to 900ms for 30-60 lines of haml. It must be something in the way how I use it, but how could I debug what's wrong? The benchmarks are consistent and reproducible.
I'm not sure about possible sources of the error:
deep partial nesting? (3-5 levels)
deep haml nesting? (4-8 levels)
use of block helpers?
lots of translations?
using haml with formtastic 2.0?
using form builders for nested forms?
Any help is appreciated.
It turned out to be a number of things inside Formtastic 2.0:
Lots of object lookups, uncached
Lots of translations, uncached
Use of try…rescue blocks which slowed it down tremendously
Fixes have been added to Formtastic 2.1 and up, making it a lot faster. Kudos to Sascha Konietzke for providing patches.
A more recent way to fix this is Hamlit, a high-performance Haml implementation with some limitations by design for performance. It claims 8.24x speedup.
Also, not Haml-specific, but look at multi-fetch gem for lists.
Most likely it's Garbage Collection. See these posts:
http://www.williambharding.com/blog/uncategorized/rails-3-performance-abysmal-to-good-to-great/comment-page-1/
http://bibwild.wordpress.com/2011/06/28/rails3-unbearably-slow-view-rendering-use-ree-with-gc-tuning/
If you're using REE 1.8.7 (which also fixes a memory leak, so you should be) then you can tune your GC settings. I just did this last week and our response time dropped by 50%.
Put in .bashrc:
export RUBY_GC_HEAP_INIT_SLOTS=1000000
export RUBY_HEAP_SLOTS_INCREMENT=500000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000
Source, and restart server
$> source ~/.bashrc
$> rails s
Depending on what is your problem, this might make rendering your partials faster (in my case, average rendering time got x3 faster).
Related
PROBLEM
We have a site on Bootstrap 3.0.2 which won't compile in Codekit, it fails on things like:
floor(#grid-gutter-width / 2);
I'm guessing Less has changed but after searching, I can't figure how it's changed. Pages I've been combing through:
https://bootstrapdocs.com/v3.0.2/docs/getting-started/
https://github.com/twbs/bootstrap/releases?after=v3.1.0
https://github.com/less/less.js/blob/master/CHANGELOG.md
QUESTIONS
In general, what's the best way of handling this without breaking everything?
Does anyone know which Less changes are causing the compile errors?
Is there a version of Bootstrap 3 that works with newer Less versions?
Or would I have to somehow run an older version of Less inside Codekit?
Any pointers in the right direction would be much appreciated.
The issue was a change in Less 1.4.0 Beta 1 & 2 (2013-03-07)
maths is now only done inside brackets. This means font: statements, media queries and the calc function can use a simpler format without being escaped. Disable this with --strict-maths-off in lessc and strictMaths:false in JavaScript.
You can use the --strict-maths-off flag but I decided to plug in Bootstrap v3.3.7 and update the theme to support the newer Bootstrap (and less).
We are currently using Ruby 1.9.3, Rails 3.1 (i know, we're working hard to upgrade all our applications).
We're using a module (let's call it 'OurModule' to add a method (let's call it 'OurAddOnMethod' to a model defined in a gem (let'd call that 'GemModel'). We have that module file living in the 'config/initializers' directory.
That file defines the module, and then calls this to include it in the model:
# Include the extension
GemModel.send(:include, OurModule)
When developing, things work well mostly, but periodically we will get an error that basically says "Undefined method 'OurAddOnMethod' in 'GemModel'". Restarting the server resolves the issue (for a while).
I'm assuming this is happening because the models are reloaded periodically with changes made in the development environment, and it appears that the initializers do not also get reloaded at that time..? It seems like this may not be the best way to set things up; it is quite frustrating to deal with.
Can anyone enlighten me on a better way to achieve this?
I ended up using wrapping the code in the following, and keeping it in initializers:
ActionDispatch::Callbacks.to_prepare do
# configure stuff or initialize
end
I feel really bad, i completely missed this question that seems to completely cover mine (linking to the answer that i used):
https://stackoverflow.com/a/8636163/287516
I working with medium Rails application which has about 60 gems dependencies. Many of these dependencies are unnecessary/useless.
Is there any way to find out which gems are not used by application?
This is not possible.
You could however start with the following:
1) Go to http://rubygems.org/ and search for gems, you think aren't 'available' anymore. If they're removed from rubygems, You can't use them anymore so Delete them from your gemfile.
2) Just look carefully into your app and just write down which ones you're sure about. The ones you aren't sure about are the ones you don't use.
3) You can use this: http://ruby-prof.rubyforge.org/ to show the called parameters, call times, memory usage and object allocations
Hope it helps you :)
A simple question. Does this version support generators?
I wanted to test out using it and follow along with Ryan Bates screen cast which I uses a different version.
I've been playing with tables today and want to see how this works using the generator with a scaffold generated model and all its components.
Running rails g bootstrap:themed returns
Could not find generator bootstrap:themed
So I tried to reinstall with rails g install:bootstrap
Error similar which lead me to try to find if it supports these commands.
Thanks
It doesn't need generators for asset files, since we hook into the asset pipeline through the use of a Rails Engine - configuration options are available through the use of variables (use this as a reference, Sass variables are actually $x rather than #x and need to be defined before importing bootstrap), Sass' #extend, and Bootstrap's #makeRow and #makeColumn mixins, along with the other Bootstrap mixins.
Themed scaffold would be interesting but generally would be a pain to maintain - view scaffolding tends to get ripped apart pretty quickly anyway. Perhaps a 'sane' application.html.erb layout generator could be useful.
So yeah, we currently have no generators, don't need an asset one, themed scaffold probably not coming soon unless someone is interested enough to do the work on it, potentially a layout generator in the pipeline.
Checkout
https://github.com/decioferreira/bootstrap-generators
Seems to be what you are asking for.
-Rick
I am in the beginning stages of diving into the world of RefineryCMS and am having an issue with the theming Engine.
I was able to customize the look of the home and blog pages, but for individual pages I create outside of the home and blog engine are not falling under the normal theme I created. I used the override method to copy all of the necessary files to my custom theme, but like I said, the page is using the default /pages/show.html.erb file vs the theme/mytheme/pages/show.html.erb file..
Any ideas on why this would be happening?
The use of the theming engine is not recommended anymore:
USE OF THE REFINERYCMS-THEMING GEM IS NO LONGER RECOMMENDED. Why?
Theming performs some strange code hacks in order to get it to work.
Therefore, it makes it difficult to keep it compatible with other
engines. Also, many people have reported over 15 second load times
with theming, whereas regularly you would get 3 second load times.
Finally, Resolve Digital no longer uses nor supports this method.
https://github.com/resolve/refinerycms-theming