Read more

Speed up better_errors

Tobias Kraze
June 26, 2017Software engineer at makandra GmbH

Current versions of better_errors already do this automatically.

If you use the Better Errors gem Show archive.org snapshot , you will sometimes notice that it can be very slow. This is because it sometimes renders a huge amount of data that will actually be hard to render for your browser.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

You can significantly improve performance by adding this to config/initializers/better_errors:

if defined?(BetterErrors) && Rails.env.development?
  module BetterErrorsHugeInspectWarning
    def inspect_value(obj)
      inspected = obj.inspect
      if inspected.size > 20_000
        inspected = "Object was too large to inspect (#{inspected.size} bytes). "
      end
      CGI.escapeHTML(inspected)
    rescue NoMethodError
      "<span class='unsupported'>(object doesn't support inspect)</span>"
    rescue Exception
      "<span class='unsupported'>(exception was raised in inspect)</span>"
    end
  end

  BetterErrors.ignored_instance_variables += [ :@_request, :@_assigns, :@_controller, :@view_renderer ]
  BetterErrors::ErrorPage.prepend(BetterErrorsHugeInspectWarning)
end

(credits to GitHub user bquorning)

Posted by Tobias Kraze to makandra dev (2017-06-26 13:00)