From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: Why is lexical binding so slow? Date: Mon, 25 Dec 2017 21:20:23 +0000 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a114844d89c25ba056130bc52" X-Trace: blaine.gmane.org 1514236778 27657 195.159.176.226 (25 Dec 2017 21:19:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 25 Dec 2017 21:19:38 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 25 22:19:33 2017 Return-path: Envelope-to: ged-emacs-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 1eTa9k-0006Yi-4g for ged-emacs-devel@m.gmane.org; Mon, 25 Dec 2017 22:19:32 +0100 Original-Received: from localhost ([::1]:36200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTaBf-0000Wa-Pe for ged-emacs-devel@m.gmane.org; Mon, 25 Dec 2017 16:21:31 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTaAm-0000WC-5D for emacs-devel@gnu.org; Mon, 25 Dec 2017 16:20:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eTaAl-0002xN-6R for emacs-devel@gnu.org; Mon, 25 Dec 2017 16:20:36 -0500 Original-Received: from mail-qt0-x22d.google.com ([2607:f8b0:400d:c0d::22d]:34847) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eTaAk-0002wz-Vx for emacs-devel@gnu.org; Mon, 25 Dec 2017 16:20:35 -0500 Original-Received: by mail-qt0-x22d.google.com with SMTP id u10so43462706qtg.2 for ; Mon, 25 Dec 2017 13:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CBr+WmR5CE+zDvLjBGroZl1hXufRvDHE42fzfwvrzLU=; b=tLruAtDkOWWBuv0cCXpOhPeprCs47gur5B6xbnf21qJsxkxKn9rLQ101Ci0hmNaEKL 1S1+rg0eLmBZ0ExKnkOJW2h7WcDmFmBUk0TOvx/u26xmJ/teE5bV/ruZVQAhnc4RLesO uoO9NPd6UtnwycCHUpX9ysBYNPXsPsAPkvqDyNtvlx+jmXJ7yT9ImRQShmooTfQY8smi YHgruniCLA8f4CJd57nI+brZsqs2lxmH9xMtWZdccRf9x474UYU7NGg4sjvJYc/I+4/C es02fTZ061f9qqzR1czC3GY/bHozbO/JIo5xvxcvYHG2WSFCFiIRKhSU//cMn2kxcC/l R3tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CBr+WmR5CE+zDvLjBGroZl1hXufRvDHE42fzfwvrzLU=; b=REUQx7sR9mPXEfzX1V+MHijQk0n/3RrroTeqnRnvy2XV6c3OOE28b0+ETF2mFLture 1RsOW+524xsdH5LaCb2+jwg99XsdKwAHhramKPIniJ4jdAEjiTeoXSGBUhn7pSA2qNaO 9lwzRvuLJzrGiN4ZYjcUA4sCGVRSkbjIsE97yeJrfgIojfhJB/JOTvODW4GByLewpQed 9DN05+VU0vJNp2GJmtscTngP/Ovir/VzE2Y64jYpEseOUoUyXfxHwa7nc8586F1P3jQ+ uP6Eyi2qf9CCPfBtub80Bcinev+GGXTdLUuJNOjwyKnVbIYstaA4o3aTy4plCsdQ1865 MnwA== X-Gm-Message-State: AKGB3mI5U+RXbrjOwzkJtY/sO2ps4bQJ9i3jSGIJe3RF6BRV3gweEiXu zh5r+Qo8ZGze8jOPc51JGXwS3VtjatWi6qIWxZQ= X-Google-Smtp-Source: ACJfBosLLYWS44gcrPGSfpqxpqNyDLAeNH5Ud5UAz4IGKDI8sLwLkGokCHCoorUIItQu9w4j6x72kTjD5cchVcdZyTI= X-Received: by 10.200.28.44 with SMTP id a41mr33615410qtk.340.1514236834226; Mon, 25 Dec 2017 13:20:34 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:221410 Archived-At: --001a114844d89c25ba056130bc52 Content-Type: text/plain; charset="UTF-8" Stefan Monnier schrieb am So., 2. Juli 2017 um 20:36 Uhr: > > https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855. > > Why is that? > > Depends on specifics, so someone would have to investigate. I that case the reason was just a dumb mistake on my part: I ran the benchmark without byte-compiled files. With byte compilation lexical binding becomes at least as fast as dynamic binding. > > Shouldn't code compiled with lexical binding be at least as > > fast as code compiled with dynamic binding? > > Not necessarily, no. E.g. when you use `mapcar` and the function > argument has free lexical variables, the lexbind code will have to build > a closure to pass to mapcar. The access to the lexical vars in the > closure will usually be faster than the corresponding access to those > vars via dynbinding, so if mapcar makes enough calls lexbind can still > be faster, but if mapcar makes few calls, dynbind is faster. > > Thanks for the explanation. --001a114844d89c25ba056130bc52 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Stefan= Monnier <monnier@iro.umontr= eal.ca> schrieb am So., 2. Juli 2017 um 20:36=C2=A0Uhr:
> h= ttps://github.com/mooz/js2-mode/issues/426#issuecomment-312506855.
> Why is that?

Depends on specifics, so someone would have to investigate.=C2=A0

I that case the reason was just a dumb mistake on my= part: I ran the benchmark without byte-compiled files. With byte compilati= on lexical binding becomes at least as fast as dynamic binding.
<= br>

> Shouldn't code compiled with lexical binding be at least as
> fast as code compiled with dynamic binding?

Not necessarily, no.=C2=A0 E.g. when you use `mapcar` and the function
argument has free lexical variables, the lexbind code will have to build a closure to pass to mapcar.=C2=A0 The access to the lexical vars in the closure will usually be faster than the corresponding access to those
vars via dynbinding, so if mapcar makes enough calls lexbind can still
be faster, but if mapcar makes few calls, dynbind is faster.


Thanks for the explanation.=C2=A0
--001a114844d89c25ba056130bc52--