From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Status: No, score=-3.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_SPAM,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from mail-ig0-f184.google.com (mail-ig0-f184.google.com [209.85.213.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id ABB1B20D58 for ; Thu, 12 May 2016 03:04:57 +0000 (UTC) Received: by mail-ig0-f184.google.com with SMTP id sq19sf12478849igc.1 for ; Wed, 11 May 2016 20:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=7V+ir/RSa5FocESjWfZXV1Jgydj+dHR4ijhcfKOOGEo=; b=dS+KA72r3330RMtkhAJt1YA56BV1+MjJeRilDg6pCxkw0Dry1a3qrhdAfw5AGrXouQ JESh4V6LKO8dK3wKlMaG843zBtyFBkXtiTqGLcqu5XSsvswDpzs6nTHNEybiqutGENha cZJ9UXfCeYuIwMymJTXDkS/uDe3JbDOWQe8iu0KXQi6i5GwR65aY8VJyhRC+lMQY2gRi aCQ3Po262pe62cSEV7jX9lbmn9zjOSuf9+EEwarKVRPHQ5SeTlL8nabnEVKer8JMTJtR DFyeVwxkej23/vbGS8yWWpc+vMChE58zpofYAkFEpgIFKSswTp1SG61ZsCsp1xplGoi5 q++A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=7V+ir/RSa5FocESjWfZXV1Jgydj+dHR4ijhcfKOOGEo=; b=PZp3qJDEX92jch/YwGoF/kNfyhYJaz7cB6jRLzi2soqF92CU3IQWNkyCjab0WUMOSY kiZXwzOYE71p+0HguFE+Jvl6hDbijmCAbT7EetvLjiaaW7vQm1ywWko0YWYxKaHU8ef8 WXr+zUoqMy0d6HxkBbjhuoYemOdBKgq39bDhvs52viN3l5TuMFYkORZPu/PQgayOBwWn Iqd1eZ6D0U1hYfk7GizoGba74C5yFcIIXEvpazUvhyBt1nJeZNJTx1oQ1Jf3uDRdCRZm bLjixXHj+xRlZ5nslV20fBi/va5r8ZmZywkqRF4Nwzv+AIa4bnWZpK3yHNAGK+t9EFXl kA0w== Sender: rack-devel@googlegroups.com X-Gm-Message-State: AOPr4FWlfEFLTPC0njx50u22Wyaju0BE0A1bPlmXg+OeVVnAawRZFycElmnLbEkNDyWs9g== X-Received: by 10.50.20.198 with SMTP id p6mr140120ige.1.1463022296996; Wed, 11 May 2016 20:04:56 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.36.31.70 with SMTP id d67ls407722itd.27.gmail; Wed, 11 May 2016 20:04:56 -0700 (PDT) X-Received: by 10.98.64.129 with SMTP id f1mr4720510pfd.10.1463022296549; Wed, 11 May 2016 20:04:56 -0700 (PDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net. [64.71.152.64]) by gmr-mx.google.com with ESMTPS id 17si1996762pfw.0.2016.05.11.20.04.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 20:04:56 -0700 (PDT) Received-SPF: pass (google.com: domain of e@80x24.org designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B2B642045C; Thu, 12 May 2016 03:04:54 +0000 (UTC) Date: Thu, 12 May 2016 03:04:54 +0000 From: Eric Wong To: rack-devel@googlegroups.com Cc: richard schneeman Subject: Re: Less allocated objects on each request Message-ID: <20160512030454.GA10916@dcvr.yhbt.net> References: <20141003200836.GA4664@dcvr.yhbt.net> <20141005081525.GA8997@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline In-Reply-To: X-Original-Sender: e@80x24.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of e@80x24.org designates 64.71.152.64 as permitted sender) smtp.mailfrom=e@80x24.org Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , richard schneeman wrote: > That first SVN commit is > > *https://github.com/ruby/ruby/commit/779ae78995977305aa5aec9cb5b562dcf54c22e7* > > The second commit is: > *https://github.com/ruby/ruby/commit/58f800a278b8b70463f4afdbb23a918d8ab441ff* > > Eric's proposal: *https://bugs.ruby-lang.org/issues/9425* > > > I agree that the patch should one day be unnecessary, Hi Richard, ressurrecting since I believe the day has come :) Since rack.git depends on Ruby 2.2.2+ which has the aforementioned string deduplication, I think we can undo most (if not all) of these ugly constants and reduce constant cache overheads while we're at it. I can followup with patches to the list hopefully in the next few weeks if nobody beats me to it (occupied with other stuff, at the moment) To summarize, the following are optimized in 2.2 (or earlier): { "foo" => "bar" } # "foo" is deduped # "bar" is duplicated unless 'frozen_string_literal: true' base_hash["foo"] = "bar" # same as above base_hash["foo"] # "foo" is deduped ditto The Hash#[] and Hash#[]= optimizations unfortunately do not transfer to subclasses like HeaderHash. # string literals in the "when" statement # this has been optimized for many years, now. case var when "foo" do_foo when "bar" do_bar end "string".freeze on any string literal is deduped since 2.1, which might be useful for performance-critical subclasses of Hash. "frozen_string_literal: true" magic comment exists since 2.3; but I'm not sure how much it helps and it's easy to introduce new bugs, so I'm not enthusiastic about it for old code. Regardless, constants are expensive in both space and time. The inline constant cache takes space, and the cache needs to be checked every time a constant is accessed. String literals do not have that cost. Constants still have one minor advantage: runtime NameError in case of typos. But I don't think that benefit is worth it as they make code harder-to-read. I mainly bring this up because I had trouble following some of the hijack code for webrick: http://mid.gmane.org/20160511050451.GA23544@dcvr.yhbt.net (Only speaking for MRI optimizations, I don't know other VMs) -- --- You received this message because you are subscribed to the Google Groups "Rack Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.