prosopite icon indicating copy to clipboard operation
prosopite copied to clipboard

The presence of N+1 queries while using Turbo causes response times to consistently increase

Open JamesChevalier opened this issue 4 years ago • 2 comments

The problem is that response times consistently and gradually increase when there is an N+1 query and prosopite is enabled and Turbo is being used. The simplest way to reproduce the issue seems to be paginating over a large set of data that includes a count of related records.

I created this repository to help easily see the issue - the readme outlines how to set it up and reproduce it: https://github.com/JamesChevalier/turbo_response_slowdown I tried to make the commits in a way that also helped give a view of only the relevant parts. This commit is the most relevant view of the issue.

Versions of relevant pieces:

  • Ruby 3.0.2
  • Rails 6.1.4.1
  • prosopite 1.0.3
  • turbo-rails 7.1.0
  • @hotwired/turbo 7.0.1

I suppose the fix is to not have N+1 queries. 😅 😆

JamesChevalier avatar Oct 16 '21 20:10 JamesChevalier

Do you mean this happens in development? As per the README, the it should not be enabled on production:

  unless Rails.env.production?
    around_action :n_plus_one_detection

    def n_plus_one_detection
      Prosopite.scan
      yield
    ensure
      Prosopite.finish
    end
  end

MatheusRich avatar Mar 07 '24 17:03 MatheusRich

Do you mean this happens in development?

Yes. I believe my reproduction repository is also set up to demonstrate that.

JamesChevalier avatar Mar 07 '24 18:03 JamesChevalier