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: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.5 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from mail-it0-x23c.google.com (mail-it0-x23c.google.com [IPv6:2607:f8b0:4001:c0b::23c]) (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 0F3F52023D for ; Thu, 29 Jun 2017 02:19:29 +0000 (UTC) Received: by mail-it0-x23c.google.com with SMTP id x12sf5800389itb.0 for ; Wed, 28 Jun 2017 19:19:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1498702768; cv=pass; d=google.com; s=arc-20160816; b=m6+VIjQ3symKllOGtD8zAkjC7W/e4ol4fTnWPF3v7tpGZTbucb7Tl7ge2ayAV6O/gK yprlf7DobnTy+wVnLA8nAwNece+M09ZMnTSZwW0bX9CarjfBLS44p6YvVOu2K4KRVBQ5 /RnW7YJ8xGNHLh/nzn3jC59m+EiIWtngB2eCtAyXPU+555CK1T7hDqGtsCvSIe2nSE2A lZSsCXAAvri7m+RNFXCaXu6ESeGpWqmUZAnoXvim4RnGAuVrty6BdWXCrhnEgi6FvQNB q6S95As+sSgXtMJSwPnB7h/b9kvQi1vChSjt4tkeXuMwb1mmDDjsXF8F2zamRCsQx/jX gRVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:references:in-reply-to :message-id:date:subject:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=VG7G3lVrM67S/Qq0IPYNR2n2PVVRq+58hBIAQTIxPVA=; b=aSn+6X0TPtFT46bmRDGL+QalU866aqVYoDL6M95bwul6PSxP7SCExUlQNbSf+gFhzx ZXynn7dC1GgKm9UZ8DFJZ0mgG4uSfeZIHIFEFmyfzI+fH5c+nObtzwMZ+ZYSUVGg+YoU mAo57hbFQ3459N8caWKj74kqUilvxnXUKzKT3gMstnuWUup5l237ufnPBWDYQrm6calN 4KWdEa8q4S0RnuCo9eg8EFF7EG6NOqf51z/ZdvazngWHZuimi8YwxRBdLt8oIEboh6tj UoA7qowuSrjgPhQM2qypTYGcQjgmNiJRKgxME/+XrimN3ImzbWKJkBd16x2fbs1wCG1y L8lA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of e@80x24.org designates 2600:3c01::f03c:91ff:fe96:f5d6 as permitted sender) smtp.mailfrom=e@80x24.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=VG7G3lVrM67S/Qq0IPYNR2n2PVVRq+58hBIAQTIxPVA=; b=IRss1AVGWCpj9HDaE6c6SfmU1RuO18NkPNw6isyfCoOJorJPg0O/v1DLYpsAMU3jJ6 8BKmlPoJYoV2RcofeD2/TMebtUJ/QAAaLE5uATBeamRrrq+KnQNwtCgVaGgYly9IhGFa j8SQitnKrPyWDGuyJI/OKBvA/Q+tM6yIBJ0zHLQsiSvYrV7kfMW9A5ajJTpPx8V1dlJw rkdSC0gPFyDVDU/0u4fkXLHfWitAelCrTkZI+pTqrVxxxzZ4MH35Zbk72wm0G2KbECbS qTGNMKskHJJGyU0K59gGVbhOgMz1LZBmqG0BLrg+YoC21XS729+M+WaBf8VWSGh0bO7g NQYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:subject:date :message-id:in-reply-to:references: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=VG7G3lVrM67S/Qq0IPYNR2n2PVVRq+58hBIAQTIxPVA=; b=N8Nbamrg03k4Ua/9guVEqqInRvfX8i70vuYsxs7GhWEdaQljpdIcafmemRNB1x2nRT aGSqqs80YgE8IBt2h3WO8N9sMaEpQG9+IG2ugDR+YWJHxl2BxHSg3BdzNB2PCi/CZMfN fDTMpBkKLJmJlteeMFjYrOvFQGNVZmr5i6omAyytOYn0JCMzE7fer7MR9XpEYCFdOyDg 2xq6VjjzCTLIUXWvSPetB56zKR08TxISrtDXDhc59kK7pHxU9D/r/OPA6l64hLDl4+Gx ibweIYFTqGh61jEHuuE++DVxH0INMATorDML///wtkYNwMXa365I3i/VlsdTFcpfJWaj eDBQ== Sender: rack-devel@googlegroups.com X-Gm-Message-State: AKS2vOwXWfRxsaeU3mGuvwWgKVPfODx7nPSh5J77KnG2e2PPiAwgrgOq yZtrLwIG+lOjZA== X-Received: by 10.36.78.203 with SMTP id r194mr270587ita.3.1498702768439; Wed, 28 Jun 2017 19:19:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rack-devel@googlegroups.com Received: by 10.36.211.144 with SMTP id n138ls3424568itg.11.gmail; Wed, 28 Jun 2017 19:19:27 -0700 (PDT) X-Received: by 10.159.61.85 with SMTP id m21mr6882800uai.25.1498702767847; Wed, 28 Jun 2017 19:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498702767; cv=none; d=google.com; s=arc-20160816; b=EfkAv2oCJ8tc1NG05Wo+uGW2EgPMYUE+PUgztwO8SA8/xn/xvcDg6hlvCU1w93yFM7 Q6O7Z9gC1Z3DblEqJSAvJkOf/1FdMGZ3lhJN7jchstgVgH+DrZUlyf064PkUc8sfVQJf jFCu2VKkOHinKKoPqs9jV6vzln/oR7uHEtL3MNiVjLYOyUztHtPxsn3WFIFhLo4jKmEM 6KM1UphmBGOY002yvdZDzJdmrQmhbEdGAbVeMnXZ+Xnq8FifgQw+CcUV7jef4vrpktyO ndxT5N3IgRVFB0ypMfP+sR6oLU6TkRD+1qrj3wQl91u2lnYZ31BIOouYw+N3Y5H5B2jm UWtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :arc-authentication-results; bh=HnDzB5+vEUweZfbnLeWQmScFp8j4SqUsc/Uefq+7vw4=; b=IuL4yvXsxvyT+DGdiZxnFLcZMx7uinT3KMBVlgFzyvGxsbw0r8lQmT5CHFeH1ZjhHl OZdbW2r9bVBzysgCaI33ranD25oBFJNIKWLPtvSeCc//PYncIZMlh9XlPZvPYkkuUmnV DWkanV1R57e8KQNr2TTo4dMFjDhzFXgpWgaFoXNp6b/j0sPFYuJKmV2271IndpOO+1UA QSKIjQsRsoJ67RbkeIdxQKg15mR4k/fF5jrbVksUIJbta4UkgPEGPAFkSJ4NIwMDKf5J CTga2HfakIy4+u3+gZz9pGdsedcNKukQMyD8Brgs2GSIckdL1BqwxVt+mCmgjUHwF53v mvEA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of e@80x24.org designates 2600:3c01::f03c:91ff:fe96:f5d6 as permitted sender) smtp.mailfrom=e@80x24.org Received: from dcvr.yhbt.net (dcvr.yhbt.net. [2600:3c01::f03c:91ff:fe96:f5d6]) by gmr-mx.google.com with ESMTPS id n20si816672pfh.14.2017.06.28.19.19.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 19:19:27 -0700 (PDT) Received-SPF: pass (google.com: domain of e@80x24.org designates 2600:3c01::f03c:91ff:fe96:f5d6 as permitted sender) client-ip=2600:3c01::f03c:91ff:fe96:f5d6; Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3BD7520288 for ; Thu, 29 Jun 2017 02:19:16 +0000 (UTC) From: Eric Wong To: rack-devel@googlegroups.com Subject: [PATCH 5/5] deflater: reduce live Time objects Date: Thu, 29 Jun 2017 02:19:15 +0000 Message-Id: <20170629021915.22517-6-e@80x24.org> In-Reply-To: <20170629021915.22517-1-e@80x24.org> References: <20170629021915.22517-1-e@80x24.org> X-Original-Sender: e@80x24.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of e@80x24.org designates 2600:3c01::f03c:91ff:fe96:f5d6 as permitted sender) smtp.mailfrom=e@80x24.org Reply-To: rack-devel@googlegroups.com Content-Type: text/plain; charset="UTF-8" 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: , Only create a Time object if the Last-Modified header exists, (immediately use the Integer result of Time#to_). Otherwise, we can rely on the default behavior of Zlib::GzipWriter of setting the mtime to the current time. While we're at it, avoid repeating the hash lookup for Last-Modified. This results in an improvement from 11.0k to 11.4k iterations/sec with the following script: require 'benchmark/ips' require 'rack/mock' req = Rack::MockRequest.env_for('', 'HTTP_ACCEPT_ENCODING' => 'gzip') response = [200, {}, []] deflater = Rack::Deflater.new(lambda { |env| response }) Benchmark.ips do |x| x.report('deflater') do s, h, b = deflater.call(req) b.each { |buf| } b.close end end --- lib/rack/deflater.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb index 821f708..0d0d021 100644 --- a/lib/rack/deflater.rb +++ b/lib/rack/deflater.rb @@ -58,8 +58,8 @@ module Rack when "gzip" headers['Content-Encoding'] = "gzip" headers.delete('Content-Length') - mtime = headers.key?("Last-Modified") ? - Time.httpdate(headers["Last-Modified"]) : Time.now + mtime = headers["Last-Modified"] + mtime = Time.httpdate(mtime).to_i if mtime [status, headers, GzipStream.new(body, mtime, @sync)] when "identity" [status, headers, body] @@ -80,7 +80,7 @@ module Rack def each(&block) @writer = block gzip =::Zlib::GzipWriter.new(self) - gzip.mtime = @mtime + gzip.mtime = @mtime if @mtime @body.each { |part| gzip.write(part) gzip.flush if @sync -- EW -- --- 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.