From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Why is lexical binding so slow? Date: Sun, 02 Jul 2017 14:36:05 -0400 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1499020616 22110 195.159.176.226 (2 Jul 2017 18:36:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Jul 2017 18:36:56 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 02 20:36:52 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 1dRjjm-0005Ho-1i for ged-emacs-devel@m.gmane.org; Sun, 02 Jul 2017 20:36:50 +0200 Original-Received: from localhost ([::1]:58900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRjjo-0003sU-9d for ged-emacs-devel@m.gmane.org; Sun, 02 Jul 2017 14:36:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRjjG-0003sO-1X for emacs-devel@gnu.org; Sun, 02 Jul 2017 14:36:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRjjB-0000xb-I6 for emacs-devel@gnu.org; Sun, 02 Jul 2017 14:36:18 -0400 Original-Received: from [195.159.176.226] (port=34066 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRjjB-0000xV-BA for emacs-devel@gnu.org; Sun, 02 Jul 2017 14:36:13 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dRjj3-0003GK-Rx for emacs-devel@gnu.org; Sun, 02 Jul 2017 20:36:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 23 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:WdrBLtchQwlZBeLm/gthEAHIxK8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:216122 Archived-At: > https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855. > Why is that? Depends on specifics, so someone would have to investigate. I remember discussing a performance problem in js2 with Dmitry a while ago (it lead to the introduction of new byte-codes controlled by byte-compile--use-old-handlers). A minor modification to the source code eliminated the performance difference between lexbind and dynbind, and the new handlers bytecodes made the lexbind case slightly faster (or maybe both cases?), IIRC. > 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. Stefan