Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active July 11, 2018 18:25
Show Gist options
  • Save SamSaffron/409805f6c8447d344e04ad68505ec43f to your computer and use it in GitHub Desktop.
Save SamSaffron/409805f6c8447d344e04ad68505ec43f to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
gem 'activerecord', '5.2.0'
gem 'memory_profiler'
gem 'benchmark-ips'
end
require 'active_record'
require 'memory_profiler'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:database => "test_db"
)
pg = ActiveRecord::Base.connection.raw_connection
pg.async_exec <<SQL
drop table if exists topics
SQL
pg.async_exec <<SQL
CREATE TABLE topics (
id integer NOT NULL,
title character varying NOT NULL,
last_posted_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
views integer DEFAULT 0 NOT NULL,
posts_count integer DEFAULT 0 NOT NULL,
user_id integer,
last_post_user_id integer NOT NULL,
reply_count integer DEFAULT 0 NOT NULL,
featured_user1_id integer,
featured_user2_id integer,
featured_user3_id integer,
avg_time integer,
deleted_at timestamp without time zone,
highest_post_number integer DEFAULT 0 NOT NULL,
image_url character varying,
like_count integer DEFAULT 0 NOT NULL,
incoming_link_count integer DEFAULT 0 NOT NULL,
category_id integer,
visible boolean DEFAULT true NOT NULL,
moderator_posts_count integer DEFAULT 0 NOT NULL,
closed boolean DEFAULT false NOT NULL,
archived boolean DEFAULT false NOT NULL,
bumped_at timestamp without time zone NOT NULL,
has_summary boolean DEFAULT false NOT NULL,
vote_count integer DEFAULT 0 NOT NULL,
archetype character varying DEFAULT 'regular'::character varying NOT NULL,
featured_user4_id integer,
notify_moderators_count integer DEFAULT 0 NOT NULL,
spam_count integer DEFAULT 0 NOT NULL,
pinned_at timestamp without time zone,
score double precision,
percent_rank double precision DEFAULT 1.0 NOT NULL,
subtype character varying,
slug character varying,
deleted_by_id integer,
participant_count integer DEFAULT 1,
word_count integer,
excerpt character varying(1000),
pinned_globally boolean DEFAULT false NOT NULL,
pinned_until timestamp without time zone,
fancy_title character varying(400),
highest_staff_post_number integer DEFAULT 0 NOT NULL,
featured_link character varying
)
SQL
class Topic < ActiveRecord::Base
end
Topic.transaction do
topic = {
}
Topic.columns.each do |c|
topic[c.name.to_sym] = case c.type
when :integer then 1
when :datetime then Time.now
when :boolean then false
else "HELLO WORLD" * 2
end
end
1000.times do |id|
topic[:id] = id
Topic.create!(topic)
end
end
$conn = ActiveRecord::Base.connection.raw_connection
class FastBase
class Relation
include Enumerable
def initialize(table)
@table = table
end
def limit(limit)
@limit = limit
self
end
def to_sql
sql = +"SELECT #{@table.columns.join(',')} from #{@table.get_table_name}"
if @limit
sql << -" LIMIT #{@limit}"
end
sql
end
def each
@results = $conn.async_exec(to_sql)
i = 0
while i < @results.cmd_tuples
row = @table.new
row.attach(@results, i)
yield row
i += 1
end
end
end
def self.columns
@columns
end
def attach(recordset, row_number)
@recordset = recordset
@row_number = row_number
end
def self.get_table_name
@table_name
end
def self.table_name(val)
@table_name = val
load_columns
end
def self.load_columns
@columns = $conn.async_exec(<<~SQL).column_values(0)
SELECT COLUMN_NAME FROM information_schema.columns
WHERE table_schema = 'public' AND
table_name = '#{@table_name}'
SQL
@columns.each_with_index do |name, idx|
class_eval <<~RUBY
def #{name}
if @recordset && !@loaded_#{name}
@loaded_#{name} = true
@#{name} = @recordset.getvalue(@row_number, #{idx})
end
@#{name}
end
def #{name}=(val)
@loaded_#{name} = true
@#{name} = val
end
RUBY
end
end
def self.limit(number)
Relation.new(self).limit(number)
end
end
class Topic2 < FastBase
table_name :topics
end
def magic
a = []
Topic2.limit(1000).each do |t|
a << t.id
end
a
end
def ar
a = []
Topic.limit(1000).each do |u|
a << u.id
end
a
end
def ar_select
a = []
Topic.select(:id).limit(1000).each do |u|
a << u.id
end
a
end
def ar_pluck
Topic.limit(1000).pluck(:id)
end
def raw_all
sql = -"select * from topics limit 1000"
ActiveRecord::Base.connection.raw_connection.async_exec(sql).column_values(0)
end
def raw
sql = -"select id from topics limit 1000"
ActiveRecord::Base.connection.raw_connection.async_exec(sql).column_values(0)
end
def test(method)
puts
puts "-"*50
puts method.to_s
puts "-"*50
send method
MemoryProfiler.report do
send method
end.pretty_print(detailed_report: false, retained_strings: false, allocated_strings: false)
end
tests = %i{
magic
ar
ar_select
ar_pluck
raw
raw_all
}
ar
tests.each do |t|
test t
end
Benchmark.ips do |b|
tests.each do |t|
b.report(t.to_s) do |i|
while i > 0
send t
i -= 1
end
end
end
end
# to run deep analysis run
# MemoryProfiler.report do
# ar
# end.pretty_print
@SamSaffron
Copy link
Author


--------------------------------------------------
magic
--------------------------------------------------
Total allocated: 84320 bytes (1012 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------
         2  " LIMIT 1000"
         2  memory.rb:117

         1  ","
         1  memory.rb:115

         1  "1000"
         1  memory.rb:117

         1  "SELECT id,title,last_posted_at,created_at,updated_at,views,posts_count,user_id,last_post_user_id,reply_count,featured_user1_id,featur
ed_user2_id,featured_user3_id,avg_time,deleted_at,highest_post_numbe"
         1  memory.rb:115

         1  "id,title,last_posted_at,created_at,updated_at,views,posts_count,user_id,last_post_user_id,reply_count,featured_user1_id,featured_user
2_id,featured_user3_id,avg_time,deleted_at,highest_post_number,image"
         1  memory.rb:115

         1  "topics"
         1  memory.rb:115


Retained String Report
-----------------------------------

--------------------------------------------------
ar
--------------------------------------------------
Total allocated: 3836287 bytes (26259 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------
      8000  "HELLO WORLDHELLO WORLD"
      8000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206377"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206378"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206379"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206386"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206393"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206398"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

      1000  "2018-06-01 06:55:39.206418"
      1000  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:89

         3  "Topic"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:41
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:48
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/scoping.rb:85

         2  "archetype"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "archived"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "avg_time"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "bumped_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "category_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "closed"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "created_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "deleted_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "deleted_by_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "excerpt"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "fancy_title"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "featured_link"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "featured_user1_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "featured_user2_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "featured_user3_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "featured_user4_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "has_summary"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "highest_post_number"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "highest_staff_post_number"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "image_url"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "incoming_link_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "last_post_user_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "last_posted_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "like_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "moderator_posts_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "notify_moderators_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "participant_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "percent_rank"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "pinned_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "pinned_globally"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "pinned_until"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "posts_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "reply_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "score"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "slug"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "spam_count"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "subtype"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "title"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "updated_at"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         2  "user_id"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128


Retained String Report
-----------------------------------

--------------------------------------------------
ar_select
--------------------------------------------------
Total allocated: 1109357 bytes (11097 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------
         5  "id"
         2  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activemodel-5.2.0/lib/active_model/attribute_methods.rb:219
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/attribute_methods.rb:230
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/result.rb:128

         3  "Topic"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:41
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:48
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/scoping.rb:85

         1  "\"$user\", public-SELECT  \"topics\".\"id\" FROM \"topics\" LIMIT $1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.r
b:658

         1  "\"topics\".\"id\""
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/to_sql.rb:729

         1  "$1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/postgresql.rb:49

         1  "1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/postgresql.rb:49

         1  "SELECT  \"topics\".\"id\" FROM \"topics\" LIMIT $1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/collectors/plain_string.rb:6

         1  "Topic Load"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/querying.rb:41


Retained String Report
-----------------------------------

--------------------------------------------------
ar_pluck
--------------------------------------------------
Total allocated: 221493 bytes (5098 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------
         5  "id"
         2  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/attribute_methods.rb:198
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activemodel-5.2.0/lib/active_model/attribute_methods.rb:219
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/attribute_methods.rb:230
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql/database_
statements.rb:83

         4  "Topic"
         2  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/scoping.rb:94
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/scoping.rb:81
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/scoping.rb:85

         1  "\"$user\", public-SELECT  \"topics\".\"id\" FROM \"topics\" LIMIT $1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/connection_adapters/postgresql_adapter.r
b:658

         1  "\"topics\".\"id\""
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/to_sql.rb:729

         1  "$1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/postgresql.rb:49

         1  "1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/visitors/postgresql.rb:49

         1  "SELECT  \"topics\".\"id\" FROM \"topics\" LIMIT $1"
         1  /home/sam/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/arel-9.0.0/lib/arel/collectors/plain_string.rb:6


Retained String Report
-----------------------------------

--------------------------------------------------
raw
--------------------------------------------------
Total allocated: 8200 bytes (4 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------

Retained String Report
-----------------------------------

--------------------------------------------------
raw_all
--------------------------------------------------
Total allocated: 8200 bytes (4 objects)
Total retained:  80 bytes (1 objects)

Allocated String Report
-----------------------------------

Retained String Report
-----------------------------------
Warming up --------------------------------------
               magic    25.000  i/100ms
                  ar     7.000  i/100ms
           ar_select    20.000  i/100ms
            ar_pluck   142.000  i/100ms
                 raw   336.000  i/100ms
             raw_all    29.000  i/100ms
Calculating -------------------------------------
               magic    257.142  (± 4.7%) i/s -      1.300k in   5.066388s
                  ar     68.106  (± 2.9%) i/s -    343.000  in   5.042919s
           ar_select    195.301  (± 4.1%) i/s -    980.000  in   5.026169s
            ar_pluck      1.406k (± 3.4%) i/s -      7.100k in   5.055234s
                 raw      3.379k (± 4.3%) i/s -     17.136k in   5.082243s
             raw_all    289.733  (± 2.1%) i/s -      1.450k in   5.006985s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment