charkost/prosopite

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

Opened this issue · 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. 😅 😆

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

Do you mean this happens in development?

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