Skip to content

Instantly share code, notes, and snippets.

View yuroyoro's full-sized avatar
🍣
🍣

しいたけ yuroyoro

🍣
🍣
View GitHub Profile
================================================================================
3.2.21 - sqlite3
================================================================================
Calculating -------------------------------------
limit 100 has_many 13.000 i/100ms
limit 100 has_many_through
5.000 i/100ms
limit 100 double has_many_through
3.000 i/100ms
require 'benchmark/ips'
begin
class CreateModels < ActiveRecord::Migration
def change
create_table :items do |t|
end
create_table :events do |t|
t.belongs_to :item
block in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner (/home/ozaki/dev/rails/activerecord/lib/active_record/associations/preloader/through_association.rb:45)
samples: 8 self (0.8%) / 332 total (33.3%)
callers:
332 ( 100.0%) ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
callees (324 total):
307 ( 94.8%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
9 ( 2.8%) ActiveRecord::Core#hash
8 ( 2.5%) block (2 levels) in ActiveRecord::Associations::Preloader::ThroughAssociation#associated_records_by_owner
code:
| 45 | through_records.each_with_object({}) { |(lhs,center),records_by_owner|
@yuroyoro
yuroyoro / ar_collection_proxy_delegates_to_association.patch
Created March 4, 2015 03:26
ActiveRecord::Associations::CollectionProxy#new の性能劣化を回復させる危険な闇patch
diff --git activerecord/lib/active_record/associations/collection_proxy.rb activerecord/lib/active_record/associations/collection_proxy.rb
index a034753..c5b84e5 100644
--- activerecord/lib/active_record/associations/collection_proxy.rb
+++ activerecord/lib/active_record/associations/collection_proxy.rb
@@ -28,13 +28,23 @@ module ActiveRecord
# is computed directly through SQL and does not trigger by itself the
# instantiation of the actual post records.
class CollectionProxy < Relation
+
delegate(*(ActiveRecord::Calculations.public_instance_methods - [:count]), to: :scope)
@yuroyoro
yuroyoro / dangerous_fasten_ar_attribute_method.patch
Created March 2, 2015 05:38
Rails4.2でのActiveRecordのcomplied attribute_methodを速くするpatch(だけどとても危険)
diff --git activerecord/lib/active_record/attribute_methods/read.rb activerecord/lib/active_record/attribute_methods/read.rb
index 20f0936..77bd11d 100644
--- activerecord/lib/active_record/attribute_methods/read.rb
+++ activerecord/lib/active_record/attribute_methods/read.rb
@@ -33,6 +33,17 @@ module ActiveRecord
end
}.new
+ TextReaderMethodCache = Class.new(AttributeMethodCache) {
+ def method_body(method_name, const_name)
@yuroyoro
yuroyoro / benchmark.rb
Created February 27, 2015 04:59
Performance regression in ActiveRecord model accessing generated property method
require 'benchmark/ips'
begin
class CreateModels < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :attribute1
t.string :attribute2
t.string :attribute3
t.string :attribute4
@yuroyoro
yuroyoro / bechmark.rb
Last active August 29, 2015 14:15
Performance regression of ActiveRecord preloading :has_many through associations | Major performance regression when preloading has_many_through association · Issue #12537 · rails/rails https://github.com/rails/rails/issues/12537#issuecomment-55462750
begin
class CreateModels < ActiveRecord::Migration
def change
create_table :items do |t|
end
create_table :events do |t|
t.belongs_to :item
end

2015年2月 迎撃!トラック泊地強襲

消費資材総計

- 燃料 弾薬 鋼材 ボーキ バケツ
E1 284 -423 -524 -38 1
E2 5431 4296 6608 1099 32
E3 2115 1411 1315 980 22
@yuroyoro
yuroyoro / client.go
Created December 17, 2014 09:28
GoでHTTP/2 最速実装 v3
/*
GoでHTTP/2 最速実装 v3
参考:
[HTTP/2 最速実装 v3 // Speaker Deck](https://speakerdeck.com/syucream/2-zui-su-shi-zhuang-v3)
[syucream/MinimumHTTP2](https://github.com/syucream/MinimumHTTP2)
[Hypertext Transfer Protocol version 2 (draft-ietf-httpbis-http2-14) 日本語訳](http://summerwind.jp/docs/draft-ietf-httpbis-http2-14/#section4-3)
[Jxck/http2](https://github.com/Jxck/http2)