• Sales: (866) 518-YARD

Archive for December, 2008

Rails Refactor Update (and Merb 1.0.7.1)

By Yehuda Katz | December 31st, 2008 at 4:12PM

Over the past few days, I’ve been working on refactoring ActionController and ActionView to clean up the interactions between them. You can follow along on my github fork. Some principles I’m following:

  • ActionController and ActionView should work well standalone
  • All request-related information should be calculated in ActionController and passed through into ActionView
  • ActionView should be responsible for figuring out what path to render; ActionController should pass enough information for ActionView to figure it out.

Based on the previous, the information passed from ActionController to ActionView will likely be: template_name, list of acceptable extensions (i.e. [:html, :xml]), prefix (usually the controller name), and partial (a boolean indicating whether the template is a partial). This is not nailed down yet, but it has so far served well.

So far, I have unified render(:template), render(:file), and render(:action) to use this new conduit, and will be working on partials tomorrow. Partials are quite complicated so my current plan may have to change slightly when I tackle them.

Interesting info: ActionPack has a lot of methods that call each other (somewhat circularly), so it wasn’t really possible to just replace the existing conduit in a straight-forward manner. Instead, I created the new method (currently called find_by_parts, which finds a template based on the components I discussed above) and slowly (very slowly) moved existing callers of find_by_path over to use find_by_parts. Thankfully, the Rails test suite caught the initial errors I made, a huge saving grace of the entire effort.

A nice side-effect of moving to a single, clean API between AC and AV is that the final code should be easier to understand. Once I’m further along, I’ll post some details of how exactly the interaction works.

We also released Merb 1.0.7.1 today to fix a few issues that were outstanding as well as a 1.0.7 development mode regression. (In general, we will be using the x.x.x.x moniker for midweek releases and x.x.x for weekly releases). The issues that were fixed:

  • Templates should reload again in development mode
  • An issue in the bundler where gems in your local repository were getting greedily installed is fixed
  • An issue that was preventing bin/thor merb:gem:install use is fixed
  • The error message when gems could not be found was slightly improved

To upgrade:

  1. gem install merb (make sure merb-gen 1.0.7.1 is installed)
  2. in your app, rm -rf tasks/merb.thor
  3. in your app, run merb-gen thor
  4. you should receive a prompt asking you to override bin/common.rb. Accept the prompt.
  5. you’re done

Happy holidays folks!

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 1% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Another Rails 2.x/3 Update

By Yehuda Katz | December 29th, 2008 at 4:12PM

I didn’t get that much done today on the Rails front as a result of getting Merb 1.0.7 out the door. I did do some more planning about how to clean up and improve the performance of ActionPack, and am really looking forward to diving into the work tomorrow.

Daniel (hassox), Michael (antares), and Carl (carllerche) have been hard at work today:

Daniel has been porting over the Merb Bootloader concept into Rails’ initializers. This is a 100% backward-compatible change that will simply make the initialization process easier to hook into (especially for plugins). This is one of the crucial components necessary for good ORM agnosticism. You can follow along at his branch. This turns out to be fairly difficult so kudos to Daniel for picking up this piece of the puzzle and getting right at it.

Michael has been going through ActiveSupport and working to make it more modular. His first major achievement is getting a new activesupport/mini.rb file that can be used by other libraries that want extensions, with a guarantee that it won’t pull in any more than is explicitly included. It includes blank?, Object#metaclass, Array extensions, Hash extensions, *attr_accessor, multibyte support, and inflections. Additional components can be required granularly, and of course, each of these components can be included granularly as well. activesupport/mini is intended to be a lightweight starting point (it weighs in at just 2.5MB) for the most common cases. Michael plans to move Templater, which currently uses Extlib, over to AS once 2.3 is released.

To quote Michael:

On the ActiveSupport front, we separate Rails-specific dependencies from others, so 3rd party applications do not get extra overhead. Right now in 2.2.2 if you do require ‘active_support’, it loads a lot of Rails specific code, like i18n gem, Builder and ActiveSupport::JSON. Since there are Ruby applications that need a convenient support library, but do not deal with the web, JSON and Builder are pure overhead, and should be loaded by the Rails components that use them.

In a follow-up to the very simple example I gave yesterday in annotating metaprogramming, Xavier Noria (fxn) went in and annotated all of the metaprogramming in the entire Rails codebase! Check out the commit. It should make it a lot easier to understand the metaprogramming sprinkled throughout the Rails codebase. Thanks to antares for the initial inspiration.

Carl has been doing some killer work to make the Merb router more flexible, and capable of handling Merb1, Rails2, and a potential Rails3 syntax with the same backend. It’s going to be really awesome to get the feature-set of the Merb router (optional segments, routing based on arbitrary request elements, inline custom code, etc.) into Rails with a shiny Railsish API. David (dhh) is already doing some killer work on designing an API for the features in the Merb router that aren’t yet in Rails that looks very promising.

We’re beginning to see that a large amount of the work that we’re doing is 100% backward compatible and can easily make it into 2.x. There’s a chance there will be a 2.4 release sometime between 2.3 and 3.0 just to roll in compatible features and cleanup, so we don’t dump the entire new feature-set on you in one fell swoop. We’ll see how that goes.

I have a small change ready to be merged into rails/master that unifies three places that did content negotiation throughout the Rails codebase. I have more work to be done on this front, but it’s a lot clearer what needs to be done now that the small bit of refactoring is done.

I hope to have some stuff on ActionPack in tomorrow’s update. I’m really looking forward to my first full work-day on Rails at Engine Yard.

See you tomorrow folks!

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 1% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

A Rails Communique

By Yehuda Katz | December 28th, 2008 at 5:12PM

After staying up until 5am last night, I slept in a bit this morning. I had lunch with Koz, his wife, and Ezra, and we got to talking some more about the issues we’ve been addressing over the past few days (we had a nice discussion about router recognition and generation, and various techniques we’ve both been using to improve performance of large route sets).

After lunch, I spent some more time thinking about how to further clean up ActionController and ActionView, and with the help of Josh and Pratik, who both recently did some refactoring work in ActionView, came up with a good plan of attack. I’ll post more details once I have some code to show, but the bottom line is that it should reduce the rendering pipeline down to a few hash lookups and a send. We already got close to this in Merb, but the recent work Josh did on ActionView provides a nice foundation for knocking this one out of the park.

Michael has continued his work on ActiveSupport, and is almost finished with a way of requiring ActiveSupport that will include only the barebones so that it can be used for third-party libraries. In particular, he would like to move Templater over from Extlib to ActiveSupport once the minimalist version has been released (the minimalist package now uses less resources than Extlib). Some details from Michael’s testing.

Daniel has been working on porting the Merb bootloader system over to Rails’ initializers, which should be 100% backward compatible but more flexible, especially for plugins.

Maybe one of these days we’ll take a day off. I hope to have some exciting code for you tomorrow!

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 1% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Merb 1.0.7 Release Notes

By Yehuda Katz | December 28th, 2008 at 4:12PM

We just released Merb 1.0.7. Some highlights:

  • merb-action-args doesn’t break when you use a exotic defaults (like [] :P )
  • merb no longer drops a pid except in daemonized or clustered mode. This fixes a bug people were having when running rake tasks or merb -i on production servers
  • fixes a bug where partials with absolute paths were not getting implicit local variables correctly
  • caches _template_for, which should improve performance
  • adds better documentation for the block parameters of the router’s defer_to
  • request() now goes through additional rack middleware, not just the default Merb application
  • fixes generated .gitignore to completely ignore gems/gems and gems/specifications
  • adds datamapper and do_sqlite3 to generated dependencies.rb
  • fixes outdated documentation in merb_mailer for using merb_mailer with TLS (gmail)
  • fixed at least one case where thor bundling was throwing an error related to full_name. If you encounter other errors, please report them immediately on the Merb tracker and tag them “bundling”
  • fixed an issue with merb-helpers where label() was ignoring passed in attributes

This is the first post-merge release of Merb. As you can see, we’re still fixing bugs at a pretty fast clip. We can chew gum and walk at the same time!

I hope everyone enjoys the rest of their weekend. I, for one, am looking forward to continuing work this week!

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 1% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

Status Memorandum

By Yehuda Katz | December 27th, 2008 at 5:12PM

Today was another great day working on improving Rails. What happened today:

I made my first commits to Rails.

The commits remove the use of method_missing in respond_to. Effectively, when you did respond_to {|format| format.html }, the format object was a Responder object that collected up the mime types you specified and then followed your instructions. However, the html method was not defined on Responder. Instead, Responder relied on method_missing to determine, on the fly, whether html was a valid mime type.

The fix was to generate methods for all known mime types in advance. In addition, when method_missing is triggered and a valid mime type is detected, Rails now generates a method on the fly (so at maximum single method_missing will be called for a particular method). The main win here is that since the method is generated, it’s not longer necessary to check whether the mime exists every time. If you get to the format.html method, that’s evidence that the mime exists, since it cannot otherwise be generated.

The upside: 8% full-stack speed-boost on both MRI and JRuby for a simple case (bringing the full-stack overhead when using respond_to down from 2.5ms to 2.3ms). It may not seem like a lot, but 0.2ms here, 0.2ms there, and pretty soon you’re talking big… amounts of time?

I did a lot of benchmarking on BlockAwareEnhancer. It turns out that for JRuby, the < %= form_for %>...< % end =%> syntax can bring down a page heavy with block helpers (1,000 block helpers to be precise) down from 30ms to 8ms. In MRI, the same technique brings the total time from 80ms to 65ms. (yes, that is a shockingly good result for JRuby… seems like there are very common, expensive operations that JRuby kicks butt on).

Carl is working hard on making the router super-easy to hook into with any front-end DSL. This will help us easily maintain backward compatibility with current Merb syntax, while giving us the ability to give Rails all the new features of the Merb router with a familiar syntax.

Michael (antares) continues his work on analyzing parts of Extlib that should go in ActiveSupport, comparing the compatibility of the modules, and bringing in new features (LazySet and DeferredModule come to mind). The idea is to make it easier to opt in to small parts of ActiveSupport with the ability to clearly know what will get pulled in as a result.

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 1% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...