Rails Micro Benchmarks!

Starting this thread to get things going!

I’ve just added benchmarks for default_scope and the results are quite shocking that I’ll review it on my local machine tomorrow.

http://rubybench.org/rails/rails/releases?result_type=activerecord/sqlite3_finders_all

There are still some benchmarks that Kirs has written but I’ve yet to activate them yet.

2 Likes

That does looks a bit odd, was expecting a regression in 4.2.0 not in 4.10

@sam I have verified and am getting the same results on my local machine.

require 'bundler/setup'
require 'rails'
require 'active_record'
require 'stackprof'

require_relative 'support/benchmark_rails.rb'

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:'
)

ActiveRecord::Migration.verbose = false

ActiveRecord::Schema.define do
  create_table :users, force: true do |t|
    t.string :name, :email
    t.boolean :admin
    t.timestamps null: false
  end
end

class User < ActiveRecord::Base
  default_scope { where(admin: true) }
end

admin = true

1000.times do
  attributes = {
    name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    email: "foobar@email.com",
    admin: admin
  }

  User.create!(attributes)

  admin = !admin
end

# Benchmark.rails("activerecord/sqlite3_finders_all", time: 10) do
StackProf.run(mode: :cpu, out: 'after.dump') do
  100000.times do
    User.all
  end
end

1 Like

@sam

New results after calling to_a on User.all.

clearly an anomaly on 3.2.4 its destroying the graph :slight_smile:

Yea I noticed that and re-ran the benchmark again. Same results. We should investigate xD

I just ran the benchmark on the local machine. Didn’t seem like there was anything wrong. User.all returns an array on Rails 3.2.4.

We need some sort of solution here, if there is an outlier result graph should still be usable.

Added mysql and postgres benchmarks.

Hmm just noticed that the anomaly disappear… http://rubybench.org/rails/rails/releases?result_type=activerecord/sqlite3_finders_all

Still needs to be fixed…