Skip to content

A platform for community discussion. Free, open, simple.

PERF: remove SQL notifiers for every SQL execution

Sam Saffron88249932a006
diff --git a/config/initializers/300-perf.rb b/config/initializers/300-perf.rb
new file mode 100644
index 00000000000..3186698a8c5
--- /dev/null
+++ b/config/initializers/300-perf.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+if Rails.env == "production"
+ # This event happens quite a lot and fans out to ExplainSubscriber
+ # and Logger, this cuts out 2 method calls that every time we run SQL
+ #
+ # In production we do not care about Explain or Logging SQL statements
+ # at this level
+ #
+ # Micro bench shows for `User.first` this takes us from 3.3k/s to 3.5k/s
+ ActiveSupport::Notifications.notifier.unsubscribe("sql.active_record")
+end