From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Brian Newsgroups: gmane.lisp.guile.devel Subject: Re: Performance impact of top level definitions Date: Tue, 15 May 2018 09:55:34 -0700 Message-ID: References: <542e7f030ad122e035a353f44465d4d3158d7f8c.camel@gmail.com> <87bmdh7hle.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1526403286 8622 195.159.176.226 (15 May 2018 16:54:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 15 May 2018 16:54:46 +0000 (UTC) Cc: guile-devel@gnu.org To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue May 15 18:54:42 2018 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fIdDk-00029R-L8 for guile-devel@m.gmane.org; Tue, 15 May 2018 18:54:40 +0200 Original-Received: from localhost ([::1]:48208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIdFr-0002g1-H5 for guile-devel@m.gmane.org; Tue, 15 May 2018 12:56:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIdDC-0000Oj-Hu for guile-devel@gnu.org; Tue, 15 May 2018 12:54:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIdDB-0005gU-SG for guile-devel@gnu.org; Tue, 15 May 2018 12:54:06 -0400 Original-Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]:46279) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIdDB-0005g8-LN for guile-devel@gnu.org; Tue, 15 May 2018 12:54:05 -0400 Original-Received: by mail-pg0-x234.google.com with SMTP id u8-v6so168385pgp.13 for ; Tue, 15 May 2018 09:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=oLSsoJmbY0coZTZTpWdIRUajMFc6lhSbGdpV3wIpTlw=; b=OhQEDEMyIJuVk5SuBs0SToUBJqMw7c2CdzyT8zzxpy3rSrJTAg9AtVHQrLQxqpexUJ 7YK98gyBdVWInBly0JGPyEYTkCdqZN/ElJlUmT3xx++C10DjdQcz8b7plGBa3IK9OntB EmlBhECkRNe1uslfHOQQ7cTTgTAgK4W7kEa0GJSY2sWjdwq853CqQtuRS7tit3VeGxpV XLxHE6Gb6rLsZo3F3IPpExsCsbW6YQiQCkDUokmPVWYucBu/SAB5wPj0rbegGBDy+EIk dUJ5HotTn3n1K/BPC4U635TZBhvdw9fcP6PyVijB/oA9XiHBh2zjX8xo8j97CpwPyfQa c9gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=oLSsoJmbY0coZTZTpWdIRUajMFc6lhSbGdpV3wIpTlw=; b=FJqVXQDFkUq3LbCCE83xbWuKGy6Dvtcbpl4ENVtpqTNtfvKYrYsyJNvAtk7uWt/dok /yaccVDZAzCoVRujuQwD4ydzGr7LAZYG9yLRLqu6oT8SpXIfDGbnNxMRr02IPe1AfZ5k EymyqH2Yr165oyvUQWorMziyuR/XHoCwJDQDm7xZp9lNVcpTy74Il1ltgxGRhU/uJLEM WZo/+yz/7lMmS0C6DLq967/otRjag6/de/yt0DZ0U0qXSyaZQ8JTjwr95TwJTqFxnUuj IkqlUxv9qFfvto2k97mV+YqRBSbh2KOzTiuvnqvTT+/cQql5HsxzUqxJ0E2ZDAFWKQK7 TOXA== X-Gm-Message-State: ALKqPwc+W+WgvIg5/D26MVfgUtcu7mcdOhou1u540quR+3otMBkrOiKh 7lyZpCyZLN6yotL8RfgzdKv0nhEy X-Google-Smtp-Source: AB8JxZo6B0U3zU1wEzBAnsvGNcXe2xIia3OdQdTd16vieuk8KPWVtIGBJ30U4I14rqq5PBWHbqJlkw== X-Received: by 2002:a62:b204:: with SMTP id x4-v6mr15839379pfe.21.1526403243982; Tue, 15 May 2018 09:54:03 -0700 (PDT) Original-Received: from yuri ([2601:602:9c01:c923:1a5e:fff:fe14:b135]) by smtp.googlemail.com with ESMTPSA id n18-v6sm916169pfg.36.2018.05.15.09.54.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 09:54:02 -0700 (PDT) In-Reply-To: <87bmdh7hle.fsf@netris.org> X-Mailer: Evolution 3.28.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::234 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19527 Archived-At: Hi Mark, Thanks for that explanation, it makes sense now to me. Cheers! On Mon, 2018-05-14 at 22:55 -0400, Mark H Weaver wrote: > Hi Brian, > > Brian writes: > > > Today I found that top level defines have a significant performance > > impact on Guile (2.2.3). The following program takes about 108 > > seconds > > to complete on my ThinkPad (an i5-5200U with Arch Linux): > > [...] > > By simply wrapping that code in a lambda the program finished in > > about > > 47 seconds. Using lets instead of defines is equally effective. > > > > I was quite surprised because I initially thought some optimization > > would just substitute those useless nodes symbols away, but it > > seems > > like that's not the case... > > Right. The problem is that toplevel variables can be mutated by > arbitrary code from other modules, e.g. by 'module-set!', so the > compiler cannot make any assumptions about what values those > variables > will contain at runtime. > > For non-toplevel variables, the situation is quite different. In > Scheme, non-toplevel variables can be accessed only from within their > lexical scope, so if such a variable is not 'set!' from within its > scope, the compiler knows that it can never be mutated. In that > case, > it can assume that the variable will always contain its initial > value, > which enables a great many optimizations including partial > evaluation. > > Mark