Optimize Firefox’s memory usage by tweaking session preferences

I’m a heavy tabbed browsing user - I have around 30 tabs open in my day-to-day Firefox profile all the time. Since the day Firefox 3 was released, I’ve noticed Firefox progressively getting slower with this particular Firefox profile (I use a different profile for web development). When it got to the point where changing tabs took a noticeable pause of 1-2 seconds, I tweaked some of Firefox’s session store and history preferences and now things are blazing fast again.

Here’s what you can do:

Go to about:config in Firefox. Type in “session” in the “Filter” box. Edit browser.sessionhistory.max_entries - this is the number of pages stored in the history of your browsing session. Basically these are pages that can be reached using your Back and Forward buttons. The default is 50 - I reduced it to 20. Edit browser.sessionhistory.max_total_viewers - this is the number of pages that are stored in RAM so that they aren’t re-processed by Firefox’s rendering engine. This is what allows you to go Back to a page in Firefox and have it load almost instantaneously. The number of pages stored actually depends on the amount of RAM on your machine (see this). I reduced this to 4 (I have 2GB RAM). Edit browser.sessionstore.max_tabs_undo - the number of tabs you can restore after closing them (you can do this with Ctrl/Cmd-Shift-T). The default of 10 is more than I really need, so I reduced it to 3 tabs. Edit browser.sessionstore.interval - Firefox saves your session after every 10 seconds by default. I changed this to a more conservative 30000 milliseconds.

You can read more about these preferences and more at the MozillaZine Knowledge Base. If you’ve any tips on how to improve Firefox’s performance, be sure to share!

Sass with Rails - avoiding disappearing stylesheets in production

A few days ago I noticed that some of the pages on the Hotels app on wego.com were completely unstyled. They turned out looking rather Jakob Nielsen-istic:

Wego.com Hotels - no CSS


But we were attached to our ugly shade of green to leave those pages in their naked glory. Preliminary CSI work told me that some cached stylesheets generated by Rails were empty files. Why is this is happening?

stylesheet_link_tag and the :cache option

Was I overriding the stylesheets generated by Rails in different pages? Because we have a lot of cobranded sites and country sites on wego.com, I use the :cache option when using stylesheet_link_tag very often.

For example, the main wego.com site’s layout template has a stylesheet_link_tag like this (in reality there are a whole lot more stylesheets):

<%= stylesheet_link_tag 'yui/reset-fonts', 'search',  :cache => 'cache/search/listings' %>

When I need to make a new page for a cobranded site, I’ll create a new layout template with this:

<%= stylesheet_link_tag 'yui/reset-fonts', 'search', "sites/#{current_site}/cobrand", :cache => "cache/#{current_site}/search/listings" %>

Oftentimes I’d copy and paste (boo and hiss all you want!) the stylesheet_link_tag from one layout template to another and forget to update the cache path (the :cache => '/path/to/stylesheet' part). Two different stylesheet sets being cached to the same path is naturally a very stupid thing to do. So this wasn’t it, but it’s good to point this out because I have made this mistake at least 2 times!

Don’t check in generated CSS files by accident

Next, since I was using Sass, I was by now pretty sure that was it. First things first: did I check in a generated CSS file into source control (we use Git)? It’s another amateur mistake, but unsurprisingly, I’ve done this a couple of times. I think I’d wasted about an hour hunting down the reason for a style change that just wouldn’t show up. Yeah, I could have just added *.css to .gitignore, but I’m still using a mix of pure CSS and Sass templates.

The problem

In the end, I found this blog post by Ari Lerner on the CitrusByte blog about similar woes with Sass in production that set me on the path to a solution. It seems that when Rails encounters stylesheet_link_tag calls, it starts to pull together all the stylesheets and sometimes Sass is unable to generate the CSS files fast enough. Rails then throws an exception about not being able to find the CSS files and outputs an empty CSS file to the cache path.

The solution

The solution? Generate all the CSS files from Sass templates prior to restarting Rails when deploying. I added a rake task for updating all the Sass stylesheets:

namespace :sass do
  desc 'Updates stylesheets if necessary from their Sass templates.'
  task :update => :environment do
    Sass::Plugin.update_stylesheets
  end
end

Then, I created a mirror of this as a Capistrano task:

namespace :sass do
  desc 'Updates the stylesheets generated by Sass'
  task :update, :roles => :app do
    invoke_command "cd #{latest_release}; RAILS_ENV=#{rails_env} rake sass:update"
  end

  # Generate all the stylesheets manually (from their Sass templates) before each restart.
  before 'deploy:restart', 'sass:update'
end

Now, whenever I do a cap deploy, the stylesheets are generated before the Rails processes are restarted, ensuring that Rails’ stylesheet_link_tag helper is always able to find the pure CSS files when trying to merge them together and caching them to a single file.

Reveal currently open files in Mac OS X

Something I noticed completely by accident today when I clicked on the titlebar of QuickTime Player today with the Cmd key held down. The “titlebar” is this thing here - I’m not sure that’s the right name for it:


Anyway, if you hold down the Cmd key (aka the Apple key), a menu pops up that shows the folder hierarchy of where the currently opened QuickTime movie is in your filesystem:


This works in all Mac apps that display the filename of the currently open/focused file in the titlebar.

It’s useful for me since my NADD means I try to close as many unused windows as possible to adhere to my Cmd-Tab diet - now I can close Finder windows after opening files and be sure that I can get back to them quickly. What about QuickSilver? Yup, I do use (and love) QuickSilver but I don’t let it catalog every single file!

Another nice thing about this is that I can easily reveal files in Finder in my favorite text editor (TextMate) without needing to use the project drawer:


Living on the Edge (of Rails) has a new home at the Official Ruby on Rails weblog

You may have heard of it, but just in case, Living on the Edge is now going to be published on the official Ruby on Rails weblog. Big thanks to Gregg Pollack for getting me the new “gig”, and more importantly, for reviving and freshening up the content on the official Rails blog.

Catch the new first edition - this one’s about the API changes since Rails 2.1.

RailsConf 2008 Day 1 - pics and a summary

Day 1 of RailsConf 2008 was basically tutorial day (schedule) and started with my colleague here with me, Arun, missing out on Yoga on Rails and me sleeping until the first tutorial session. Anyway, I snapped some photos while trying to remain the unobtrusive tourist.

Here’s a shot of Portland Convention Center where it’s all happening:

Portland Convention Center - twin peaks outside


There’re queues for collection of badges after registering your attendance:

RailsConf Day 1 - registration queue


Patience in the queue rewarded me with a RailsConf badge/name tag:

RailsConf badge


I was at the Meta-programming Ruby for Fun & Profit tutorial in the morning. I think when I selected the tutorial it was before I’d seen Neal Ford and Patrick Farley’s (the speakers) presentation videos from elsewhere - I know Patrick presented at MWRC and enjoyed that video.

RailsConf day 1 - metaprogramming tutorial


So anyway, after the break I went over to the Refactoring Your Rails Application tutorial. Was pretty good, but I didn’t learn much I didn’t already know.

Lunch came in the form of a pretty box:

RailsConf day 1 - lunch


After lunch was the 2nd tutorial session and I went to both CI for the Rails Guy (or Gal) (by Chad Woolley) and Developer Testing Tricks (by Brian Takita). There were some scathing comments about how the tutorials were rather underwhelming so far in #railsconf on IRC. While I agree that the tutorials were rather underwhelming, I think I should have expected it. Oh well, I’ll know to skip them next time.

Later that night, at the Birds of a Feather session, after stealing a Pivotal Labs t-shirt (they’re launching a bug tracker, project management type app called Pivotal Tracker at RailsConf), Yehuda Katz (Merb and jQuery ninja) gave a presentation on Merb (geared towards Rails folks). It was a pretty interesting talk though there wasn’t much above what Ezra had presented previously at GoRuCo 2008 and at MWRC 2008 (I think Yehuda did one too but I can’t remember where now). Yehuda pointed out a (heated) discussion that happened recently on keeping Merb syntax as Rails-friendly as possible. I have no objection against a different syntax really, especially since Merb looks pretty well-documented in the source itself - would be nice if someone could point out an up-to-date Merb tutorial though.

Anyway, that’s it from me - as always, if anyone who reads my blog recognizes me at RailsConf, do say hi (#railsconf works too).


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser