This project is archived and is in readonly mode.

#1158 ✓resolved
Scott Windsor

Rails.env.environment? extremely slow

Reported by Scott Windsor | October 2nd, 2008 @ 04:58 PM | in 2.x

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).

Comments and changes to this ticket

  • Scott Windsor

    Scott Windsor October 3rd, 2008 @ 10:15 PM

    • 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.

  • Tarmo Tänav

    Tarmo Tänav October 3rd, 2008 @ 10:21 PM

    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.

  • Pratik

    Pratik October 21st, 2008 @ 01:15 AM

    • State changed from “new” to “resolved”
    • Tag changed from 2.1.1, performance to 2.1.1, performance
  • Stephen Touset

    Stephen Touset March 1st, 2009 @ 08:37 PM

    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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages