summaryrefslogtreecommitdiff
path: root/ChangeLog
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-26 16:05:52 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-26 16:05:52 +0000
commit7fa21558051e5412dcb790f528e392476edd4389 (patch)
treed235c9c05484654921c94b69485a77dce6eb2454 /ChangeLog
parent0d71c07d4995afda231d0fdebf625744b8e3418a (diff)
* lib/ostruct.rb: Move method definitions for getter/setter to be lazy
Patch by @sferik in [GH-1033]: https://github.com/ruby/ruby/pull/1033 Instead of defining two methods -- a reader and writer -- for each OpenStruct attribute when it is initialized, define them lazily, the first time either one is called. This adheres to the principle of "pay for use": methods that are never accessed are never defined. This optimization makes initialization an order of magnitude faster for objects with 100 attributes. In the worst-case scenario, where every attribute is accessed, performance is no worse than it is today. Benchmark --------- require 'benchmark/ips' require 'ostruct' N = 100 ATTRS = (:aa..:zz).take(N) HASH = Hash[ATTRS.map { |x| [x, x] }] def ostruct OpenStruct.new(HASH) end Benchmark.ips do |x| x.report('ostruct') { ostruct } end ------------------------------------------------- before 2.279k (± 8.8%) i/s - 11.395k after 24.702k (±12.8%) i/s - 122.600k ------------------------------------------------- git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ChangeLog')
-rw-r--r--ChangeLog5
1 files changed, 5 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 2023dd9f9a..f5b97353f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Sep 27 00:34:31 2015 Zachary Scott <zzak@ruby-lang.org>
+
+ * lib/ostruct.rb: Move method definitions for getter/setter to be lazy
+ Patch by @sferik in [GH-1033]: https://github.com/ruby/ruby/pull/1033
+
Fri Sep 25 10:07:25 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* lib/net/http.rb: removed unused variable. It's removed at r13648.