Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails.env.environment? extremely slow

#1158

The new feature introduce in Rails 2.1.1 to allow StringQuestioneer for environment is much slower than comparing environments.

Here's the checkin... http://github.com/rails/rails/co...

$./script/performance/benchmarker 'Rails.env.development?'

        user     system      total        real

#1 0.000000 0.000000 0.000000 ( 0.001687) $./script/performance/benchmarker "ENV['RAILS_ENV'] == 'development'"

        user     system      total        real

#1 0.000000 0.000000 0.000000 ( 0.000024)

Attached is the full profile. Rails.env should at least memoize these calls since they are very expensive (and the rails environment is not going to change once an application starts).

Reported by Scott Windsor · October 2nd, 2008 @ 04:58 PM

State: resolved
Milestone: 2.x
Assigned to: Tarmo Tänav Tarmo Tänav
Importance: none

Activity

  1. Scott Windsor
    Scott Windsor
    • Assigned user set to Tarmo Tänav

    Upon further investigation, the reason this is slow is that the Rails.env method call is requiring 'active_support/string_inquirer' in every single method call.

    This was introduced in the following git commit... http://github.com/rails/rails/co...

    This require isn't needed and can be taken out. I've attached a patch that includes both a fix and a unit test verifying the fix.

    I'm also re-assigning this ticket to Tarmo since he introduced the bug.

    October 3rd, 2008 @ 10:15 PM

  2. Tarmo Tänav
    Tarmo Tänav

    The reason the require line was added was that the railties library does not load active_support and thus one could not call "Rails.env.production?" inside the initializer block in environment.rb.

    If you can make that work without using the require line (perhaps by making railties load the inquirer separately), then I'm sure the patch will be accepted.

    October 3rd, 2008 @ 10:21 PM

  3. Pratik
    Pratik
    • State changed from new to resolved
    • Tag changed from 2.1.1, performance to 2.1.1, performance

    October 21st, 2008 @ 01:15 AM

  4. Stephen Touset
    Stephen Touset

    The fix to this seems to have been reverted, and the file is no longer being required at all in initializer.rb. This causes things like "Rails.env.test?" to fail in config/environment.rb.

    March 1st, 2009 @ 08:37 PM