Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Nov 21, 2012
  1. @jonleighton

    Don't allocate new strings in compiled attribute methods

    jonleighton authored
    This improves memory and performance without having to use symbols which
    present DoS problems. Thanks @headius and @tenderlove for the
    suggestion.
    
    This was originally committed in
    f176501, and then reverted in
    d349490 due to it causing problems in a
    real application. This second attempt should solve that.
    
    Benchmark
    ---------
    
    require 'active_record'
    require 'benchmark/ips'
    
    ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
    
    class Post < ActiveRecord::Base
      connection.create_table :posts, force: true do |t|
        t.string :name
      end
    end
    
    post = Post.create name: 'omg'
    
    Benchmark.ips do |r|
      r.report('Post.new')          { Post.new name: 'omg' }
      r.report('post.name')         { post.name }
      r.report('post.name=')        { post.name = 'omg' }
      r.report('Post.find(1).name') { Post.find(1).name }
    end
    
    Before
    ------
    
    Calculating -------------------------------------
                Post.new      1419 i/100ms
               post.name      7538 i/100ms
              post.name=      3024 i/100ms
       Post.find(1).name       243 i/100ms
    -------------------------------------------------
                Post.new    20637.6 (±12.7%) i/s -     102168 in   5.039578s
               post.name  1167897.7 (±18.2%) i/s -    5186144 in   4.983077s
              post.name=    64305.6 (±9.6%) i/s -     317520 in   4.998720s
       Post.find(1).name     2678.8 (±10.8%) i/s -      13365 in   5.051265s
    
    After
    -----
    
    Calculating -------------------------------------
                Post.new      1431 i/100ms
               post.name      7790 i/100ms
              post.name=      3181 i/100ms
       Post.find(1).name       245 i/100ms
    -------------------------------------------------
                Post.new    21308.8 (±12.2%) i/s -     105894 in   5.053879s
               post.name  1534103.8 (±2.1%) i/s -    7634200 in   4.979405s
              post.name=    67441.0 (±7.5%) i/s -     337186 in   5.037871s
       Post.find(1).name     2681.9 (±10.6%) i/s -      13475 in   5.084511s
Commits on Oct 12, 2012
  1. @jonleighton

    Don't allocate new strings in compiled attribute methods

    jonleighton authored
    This improves memory and performance without having to use symbols which
    present DoS problems. Thanks @headius and @tenderlove for the
    suggestion.
    
    Benchmark
    ---------
    
    require 'active_record'
    require 'benchmark/ips'
    
    ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database:
    ':memory:')
    
    class Post < ActiveRecord::Base
      connection.create_table :posts, force: true do |t|
        t.string :name
      end
    end
    
    post = Post.create name: 'omg'
    
    Benchmark.ips do |r|
      r.report('Post.new')          { Post.new name: 'omg' }
      r.report('post.name')         { post.name }
      r.report('post.name=')        { post.name = 'omg' }
      r.report('Post.find(1).name') { Post.find(1).name }
    end
    
    Before
    ------
    
    Calculating -------------------------------------
                Post.new      1419 i/100ms
               post.name      7538 i/100ms
              post.name=      3024 i/100ms
       Post.find(1).name       243 i/100ms
    -------------------------------------------------
                Post.new    20637.6 (±12.7%) i/s -     102168 in   5.039578s
               post.name  1167897.7 (±18.2%) i/s -    5186144 in   4.983077s
              post.name=    64305.6 (±9.6%) i/s -     317520 in   4.998720s
       Post.find(1).name     2678.8 (±10.8%) i/s -      13365 in   5.051265s
    
    After
    -----
    
    Calculating -------------------------------------
                Post.new      1431 i/100ms
               post.name      7790 i/100ms
              post.name=      3181 i/100ms
       Post.find(1).name       245 i/100ms
    -------------------------------------------------
                Post.new    21308.8 (±12.2%) i/s -     105894 in   5.053879s
               post.name  1534103.8 (±2.1%) i/s -    7634200 in   4.979405s
              post.name=    67441.0 (±7.5%) i/s -     337186 in   5.037871s
       Post.find(1).name     2681.9 (±10.6%) i/s -      13475 in   5.084511s
  2. @jonleighton

    Revert "Key the attributes hash with symbols"

    jonleighton authored
    This reverts commit 86c3dfb.
    
    Conflicts:
    	activerecord/lib/active_record/attribute_methods/read.rb
    
    Reason: whilst this increased performance, it also presents a DoS risk
    via memory exhaustion if users were allowing user input to dictate the
    arguments of read/write_attribute. I will investigate alternative ways
    to cut down on string allocations here.
Commits on Aug 31, 2012
  1. @jonleighton

    Key the attributes hash with symbols

    jonleighton authored
    This is a performance/GC optimisation.
    
    In theory, this could be optimised by the implementation (last time I
    checked, this would have no effect on JRuby). But in practise, this make
    attribute access faster.
Commits on Dec 15, 2011
  1. @jonleighton
Commits on Nov 30, 2011
  1. @jonleighton

    consistency

    jonleighton authored
  2. @jonleighton

    omg computer science!

    jonleighton authored
    Implement a mini state machine for serialized attributes. This means we
    do not have to deserialize the values upon initialization, which means
    that if we never actually access the attribute, we never have to
    deserialize it.
  3. @jonleighton
Commits on Oct 5, 2011
  1. @jonleighton

    Revert "Raise error on unknown primary key."

    jonleighton authored
    This reverts commit ee2be43.
  2. @jonleighton

    Raise error on unknown primary key.

    jonleighton authored
    If we don't have a primary key when we ask for it, it's better to fail
    fast. Fixes GH #2307.
Commits on Sep 12, 2011
  1. @jonleighton

    Raise error when using write_attribute with a non-existent attribute.

    jonleighton authored
    Previously we would just silently write the attribute. This can lead to
    subtle bugs (for example, see the change in AutosaveAssociation where a
    through association would wrongly gain an attribute.
    
    Also, ensuring that we never gain any new attributes after
    initialization will allow me to reduce our dependence on method_missing.
  2. @jonleighton
Something went wrong with that request. Please try again.