From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 7A75019E0040 for ; Mon, 28 Dec 2015 00:16:16 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 6D033B5D885 for ; Mon, 28 Dec 2015 00:48:48 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 2DD8918CC7B6 for ; Mon, 28 Dec 2015 00:48:49 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4D6981205A0; Mon, 28 Dec 2015 00:48:48 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id DDEED120483 for ; Mon, 28 Dec 2015 00:48:44 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=qoCwgiHP13ciGFCPf0zEg/RehtU=; b=b524xwealcmKCp36Lv rPPtcJ+0tyhtFk5DRxWfjpBHX+qA+OQu73GVaVXP4JMsYKl80s32dLaqffQrKvj9 aPb1MyGnw1siLsMnuDUkfCSCfofKJnF1BthdjcRVLaNSvv1X+0vEjxVyWySaP63J RPO3LeyV0IfFTAtaoE25DOmOA= Received: by filter0605p1mdw1.sendgrid.net with SMTP id filter0605p1mdw1.8385.5680085540 2015-12-27 15:48:37.76215446 +0000 UTC Received: from herokuapp.com (ec2-54-221-74-83.compute-1.amazonaws.com [54.221.74.83]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id SFob742VTSSChEuHK2ntJw for ; Sun, 27 Dec 2015 15:48:38.212 +0000 (UTC) Date: Sun, 27 Dec 2015 15:48:38 +0000 From: ariel.caplan@mail.yu.edu To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 47123 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11901 X-Redmine-Issue-Author: amcaplan X-Redmine-Issue-Assignee: marcandre X-Redmine-Sender: amcaplan X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4XMPDLPszhV0457hBl5HyAeMHptHhYAFY0gP eLBef2zYgXrx9yzs3FlqzxgTuxHD6xotZCc/dKWokz0+dcKqxmffJLzu8UOFLxf5r3yVvtqcI++fkL +TvLf0nD8hwDeTgZaF6fP9OKZG/uvSWyWl8og2XtOPr44iGkCVEe2buTFw== X-ML-Name: ruby-core X-Mail-Count: 72524 Subject: [ruby-core:72524] [Ruby trunk - Bug #11901] Performance Issue with OpenStruct X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11901 has been updated by Ariel Caplan. Assignee set to Marc-Andre Lafortune To be more specific (but not clog up the description), the problem can be traced to https://github.com/ruby/ruby/blob/b8d9770b6c699af6e63dab727621777fbfbf7b44/lib/ostruct.rb#L166 where the methods are only defined if `#respond_to?` is `false` for that method name. Since `#repond_to_missing?` was overridden to report `true` when the key is in the table (https://github.com/ruby/ruby/blob/b8d9770b6c699af6e63dab727621777fbfbf7b44/lib/ostruct.rb#L176), the methods are never defined. ---------------------------------------- Bug #11901: Performance Issue with OpenStruct https://bugs.ruby-lang.org/issues/11901#change-55788 * Author: Ariel Caplan * Status: Open * Priority: Normal * Assignee: Marc-Andre Lafortune * ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13] * Backport: ---------------------------------------- After recent changes to define OpenStruct getter/setter methods lazily, there is a heavy performance impact for the use case where an attribute is assigned at initialization time (i.e. `Openstruct.new(foo: :bar)`). Once an attribute is stored in the internal hash, the appropriate singleton methods will never be defined, due to the recent changes to OpenStruct's `#respond_to_missing?` - meaning that every time I call `#foo` or `#foo=` it relies on `#method_missing`. Benchmark using benchmark-ips is attached. I'm primarily concerned about the case of configuration objects, which may be populated at initialization time and then accessed many times throughout the life of the program. ---Files-------------------------------- openstruct-regression-benchmark.rb (1.36 KB) -- https://bugs.ruby-lang.org/