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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)