Created
June 17, 2021 19:20
Revisions
-
ghiculescu created this gist
Jun 17, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem "rails", github: "rails/rails", branch: "main" # gem "rails", github: "ghiculescu/rails", branch: "has-many-build-perf-regression" gem "sqlite3" gem "benchmark-ips" end require "active_record" require "active_support" require "logger" ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Schema.define do create_table :authors, force: true do |t| end create_table :posts, force: true do |t| t.references :author end end class Author < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :author end author = Author.create! posts = 100_000.times.map { |n| { author_id: author.id } } Post.insert_all(posts) author = Author.find(author.id) author.posts.load_target Benchmark.ips do |x| x.report("main branch") { author.posts.build } # x.report("my branch") { author.posts.build } x.compare! end