From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: [patch] generator function optimizations Date: Sun, 12 Mar 2017 11:59:44 +0100 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=94eb2c1b4bb0156d6f054a867e4b X-Trace: blaine.gmane.org 1489316394 22396 195.159.176.226 (12 Mar 2017 10:59:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Mar 2017 10:59:54 +0000 (UTC) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 12 11:59:50 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 1cn1E3-0004yR-Fq for ged-emacs-devel@m.gmane.org; Sun, 12 Mar 2017 11:59:47 +0100 Original-Received: from localhost ([::1]:46511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cn1E9-0001Ed-GB for ged-emacs-devel@m.gmane.org; Sun, 12 Mar 2017 06:59:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cn1E3-0001EW-Gd for emacs-devel@gnu.org; Sun, 12 Mar 2017 06:59:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cn1E2-0001V4-Bi for emacs-devel@gnu.org; Sun, 12 Mar 2017 06:59:47 -0400 Original-Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]:33285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cn1E2-0001Us-5i for emacs-devel@gnu.org; Sun, 12 Mar 2017 06:59:46 -0400 Original-Received: by mail-pf0-x235.google.com with SMTP id w189so58467247pfb.0 for ; Sun, 12 Mar 2017 03:59:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=KDUvMiVDlbKAX4r4JypoUuRuhqduevysPOW253Jj6QE=; b=ilSqyLBm1eRXMPTJ7aC2aY3vcg5hyeurk8cw5vAMVpEQgYGf7+eaxgHrZ8PCY0OClw 5+TiQGXphFsAhfzDU5nnvOfxIfnogaBwIwFbbTeVRYH9v9VEj1P3TxYs+agOx7Yo9KYB LM12S7kFXUROLuME8RMEO9aG4/SwxvCdN9dvcf7oYwwX8I++1jmtc8PT43lR7ONqulcf PDU8/TA6bixLGsU8u49ZiUcWFjExrjy7/crWdBwaWeJYbZbETQmARtinRNmkL0TmuLjy dbKnjVZCK+jYkut4pTtLUqkvruLrBeW6i3d4xO/zXs9vQxayTCDEX+AZCxWIf6aQ8Xe2 gkYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KDUvMiVDlbKAX4r4JypoUuRuhqduevysPOW253Jj6QE=; b=K7GjY8O3kbPld1VCDegFA86ghH7eVK2q0yH+P/4mm5tzKGbCOZgB6jPiH8lcHzgkrX MMKL6IzbbWXLLSHxSHQyYMcuM2Fs4Rple8Pj7xa60vFH3+AlT9CwfiIxuX9v0WA+dZph yEj5cL5yyj6Qd+VED4KKB3kaXmDHZ/eQJQv7haOBtRYXGOBqpaaPFBsibDunbeYzEbkr h7rR8QIZmU7DDVUrbE1HRFOWQx+bo/+nRtqLvKczziBNkuBUeo2thfgZbMdpA7WrcECN c9MJ+pBm50DH0hnNMiszh37OxDxW8tH3kadrQ81RnxryYmhtuOUVsoEK+PO9QfIFj1Mx rwtw== X-Gm-Message-State: AMke39kFrs5m1JJgo25yg1W1HEg491zTEKwKqmI1+vG7yLdhlLtWXZ+s+wBwt64AFi3ODAIgMDttyUftsdlOBA== X-Received: by 10.99.127.27 with SMTP id a27mr30034491pgd.87.1489316384951; Sun, 12 Mar 2017 03:59:44 -0700 (PDT) Original-Received: by 10.100.176.176 with HTTP; Sun, 12 Mar 2017 03:59:44 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::235 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:212937 Archived-At: --94eb2c1b4bb0156d6f054a867e4b Content-Type: text/plain; charset=UTF-8 Generator functions are translated into a set of closures that work together. While documentation says that they are "somewhat less efficient than conventional elisp routines", that seems to be an understatement. In my real code (a very large function used as a co-routine) with 60 yields, generator function has over 1000 lambdas. I see several ways to improve this at least somewhat. The patch below improves transformation of `progn' forms. Here it results in 30 lambdas in the generator function fewer. Not great (~ -3%), but I guess in other cases it can give a larger improvement. All unit-tests pass. If this patch is accepted, I can work on some other ideas I have. Paul * lisp/emacs-lisp/generator.el (cps--transform-1): When transforming `progn' form with several atomic forms at the beginning, create only one state for all of them. --94eb2c1b4bb0156d6f054a867e4b Content-Type: text/plain; charset=US-ASCII; name="generators.diff" Content-Disposition: attachment; filename="generators.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_j06khrud0 ZGlmZiAtLWdpdCBhL2xpc3AvZW1hY3MtbGlzcC9nZW5lcmF0b3IuZWwgYi9saXNwL2VtYWNzLWxp c3AvZ2VuZXJhdG9yLmVsCmluZGV4IDJhYjAxNDA0YmEuLmEzNDYyOTcxZjggMTAwNjQ0Ci0tLSBh L2xpc3AvZW1hY3MtbGlzcC9nZW5lcmF0b3IuZWwKKysrIGIvbGlzcC9lbWFjcy1saXNwL2dlbmVy YXRvci5lbApAQCAtMjg2LDE5ICsyODYsMjUgQEAgZG9uJ3QgeWllbGQuIikKICAgICA7OyBQcm9j ZXNzIGBwcm9nbicgYW5kIGBpbmxpbmUnOiB0aGV5IGFyZSBpZGVudGljYWwgZXhjZXB0IGZvciB0 aGUKICAgICA7OyBuYW1lLCB3aGljaCBoYXMgc29tZSBzaWduaWZpY2FuY2UgdG8gdGhlIGJ5dGUg Y29tcGlsZXIuCiAKLSAgICAoYChpbmxpbmUpIChjcHMtLXRyYW5zZm9ybS0xIG5pbCBuZXh0LXN0 YXRlKSkKLSAgICAoYChpbmxpbmUgLGZvcm0pIChjcHMtLXRyYW5zZm9ybS0xIGZvcm0gbmV4dC1z dGF0ZSkpCi0gICAgKGAoaW5saW5lICxmb3JtIC4gLHJlc3QpCi0gICAgICAoY3BzLS10cmFuc2Zv cm0tMSBmb3JtCi0gICAgICAgICAgICAgICAgICAgICAgICAoY3BzLS10cmFuc2Zvcm0tMSBgKGlu bGluZSAsQHJlc3QpCi0gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBu ZXh0LXN0YXRlKSkpCi0KLSAgICAoYChwcm9nbikgKGNwcy0tdHJhbnNmb3JtLTEgbmlsIG5leHQt c3RhdGUpKQotICAgIChgKHByb2duICxmb3JtKSAoY3BzLS10cmFuc2Zvcm0tMSBmb3JtIG5leHQt c3RhdGUpKQotICAgIChgKHByb2duICxmb3JtIC4gLHJlc3QpCi0gICAgICAoY3BzLS10cmFuc2Zv cm0tMSBmb3JtCi0gICAgICAgICAgICAgICAgICAgICAgICAoY3BzLS10cmFuc2Zvcm0tMSBgKHBy b2duICxAcmVzdCkKLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5l eHQtc3RhdGUpKSkKKyAgICAoYCgsKG9yICdpbmxpbmUgJ3Byb2duKSkgKGNwcy0tdHJhbnNmb3Jt LTEgbmlsIG5leHQtc3RhdGUpKQorICAgIChgKCwob3IgJ2lubGluZSAncHJvZ24pICxmb3JtKSAo Y3BzLS10cmFuc2Zvcm0tMSBmb3JtIG5leHQtc3RhdGUpKQorICAgIChgKCwoYW5kIChvciAnaW5s aW5lICdwcm9nbikgcHJvZ24tdHlwZSkgLGZvcm0gLiAscmVzdCkKKyAgICAgIChsZXQgKGF0b21p Yy1oZWFkKQorICAgICAgICA7OyBXaGVuIHRoZXJlIGFyZSBzZXZlcmFsIGF0b21pYyAoaS5lLiB3 aXRob3V0IGBpdGVyLXlpZWxkJykKKyAgICAgICAgOzsgZm9ybXMgYXQgdGhlIGJlZ2lubmluZywg ZG9uJ3QgY3JlYXRlIGEgc2VwYXJhdGUgc3RhdGUgZm9yCisgICAgICAgIDs7IGVhY2ggb2YgdGhl bSwgYnV0IHJhdGhlciBvbmUgZm9yIGFsbC4KKyAgICAgICAgKHVubGVzcyBjcHMtaW5oaWJpdC1h dG9taWMtb3B0aW1pemF0aW9uCisgICAgICAgICAgKHdoZW4gKGNwcy0tYXRvbWljLXAgZm9ybSkK KyAgICAgICAgICAgIChzZXRmIGF0b21pYy1oZWFkIChsaXN0IGZvcm0pKQorICAgICAgICAgICAg KHdoaWxlIChhbmQgcmVzdCAoY3BzLS1hdG9taWMtcCAoY2FyIHJlc3QpKSkKKyAgICAgICAgICAg ICAgKHB1c2ggKHBvcCByZXN0KSBhdG9taWMtaGVhZCkpKSkKKyAgICAgICAgKGlmIGF0b21pYy1o ZWFkCisgICAgICAgICAgICAoY3BzLS1tYWtlLWF0b21pYy1zdGF0ZSBgKCxwcm9nbi10eXBlICxA KG5yZXZlcnNlIGF0b21pYy1oZWFkKSkKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgIChjcHMtLXRyYW5zZm9ybS0xIGAoLHByb2duLXR5cGUgLEByZXN0KQorICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV4dC1zdGF0ZSkpCisg ICAgICAgICAgKGNwcy0tdHJhbnNmb3JtLTEgZm9ybQorICAgICAgICAgICAgICAgICAgICAgICAg ICAgIChjcHMtLXRyYW5zZm9ybS0xIGAoLHByb2duLXR5cGUgLEByZXN0KQorICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5leHQtc3RhdGUpKSkpKQogCiAgICAg OzsgUHJvY2VzcyBgbGV0JyBpbiBhIGhlbHBlciBmdW5jdGlvbiB0aGF0IHRyYW5zZm9ybXMgaXQg aW50byBhCiAgICAgOzsgbGV0KiB3aXRoIHRlbXBvcmFyaWVzLgo= --94eb2c1b4bb0156d6f054a867e4b--