From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#38104: 27.0.50; elixir-mode fontification is very slow Date: Wed, 27 Nov 2019 23:58:46 +0200 Message-ID: <6deedf54-c3d6-bc41-efb9-e3f85e2a1f05@yandex.ru> References: <3b0bfb66-437d-3606-dc06-05957f01b516@yandex.ru> <2ec58f9d-b979-7ad1-d53f-4cc454e50395@yandex.ru> <01F6BECA-B48A-4B8F-BFBC-1FBED482864F@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="261279"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Cc: 38104-done@debbugs.gnu.org To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 27 22:59:19 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ia5LC-0015qf-UP for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Nov 2019 22:59:19 +0100 Original-Received: from localhost ([::1]:43582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ia5LB-000329-Pv for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Nov 2019 16:59:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54072) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ia5Kx-0002nw-Ax for bug-gnu-emacs@gnu.org; Wed, 27 Nov 2019 16:59:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ia5Kv-0003uU-Tl for bug-gnu-emacs@gnu.org; Wed, 27 Nov 2019 16:59:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ia5Kv-0003uN-QW for bug-gnu-emacs@gnu.org; Wed, 27 Nov 2019 16:59:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ia5Kv-0008E0-QP for bug-gnu-emacs@gnu.org; Wed, 27 Nov 2019 16:59:01 -0500 Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Wed, 27 Nov 2019 21:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 38104 X-GNU-PR-Package: emacs Mail-Followup-To: 38104@debbugs.gnu.org, dgutov@yandex.ru, dgutov@yandex.ru Original-Received: via spool by 38104-done@debbugs.gnu.org id=D38104.157489193731600 (code D ref 38104); Wed, 27 Nov 2019 21:59:01 +0000 Original-Received: (at 38104-done) by debbugs.gnu.org; 27 Nov 2019 21:58:57 +0000 Original-Received: from localhost ([127.0.0.1]:56322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ia5Kr-0008Dc-7q for submit@debbugs.gnu.org; Wed, 27 Nov 2019 16:58:57 -0500 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:33788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ia5Kp-0008DM-2l for 38104-done@debbugs.gnu.org; Wed, 27 Nov 2019 16:58:56 -0500 Original-Received: by mail-wr1-f41.google.com with SMTP id w9so28634784wrr.0 for <38104-done@debbugs.gnu.org>; Wed, 27 Nov 2019 13:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/KK/IAiJ3ebl0p7skrWNsO9gEdMOyhTHcMT6wKHPjWs=; b=D8KMfvfbpOwsabFHYxUhDOl66ObuOtKU+hLt7EQHFPLvTmrQp4fUuO4pgyGTTAKkTg L08aE9krhsWsvOH3MQa9kJoYui987wB09oIeiBL6Ob1Mao+LZ5HqrIK5jO75D6zbU/A/ x+HWJKcuKmEPn4hDRYN75Bh5wvoY10K7SZMQDsHLB4glYSW1OiDRy6i8IL3StQGf6wjg VE/GLR2/ft+A/fFHb1I+RYM7oBkrnMEZBkp6oClRl0fKmysFIGckYzzna8kallJFlV2g yHgROBlfCbvrDTEWhStHFD0spbZPhA6Lv39SVWQdd4NzJ6O7NUJQ6RWCi0CG2U8hv/Ux lfMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/KK/IAiJ3ebl0p7skrWNsO9gEdMOyhTHcMT6wKHPjWs=; b=oiDDthWFeq27d21MMBHhyv9fRd/Qm67OhJU0e2O5f9ElJbR/Ywt2HkOVVs5l9rEzVd Aqw9ijlYxJuq09oAZ0emVsaiYwRutc+puaN73RkXbgLVqKKGdHGfvS4qAg/4F39wX5X5 sWa9l+RZAtv8MInq6UBvsE8OHJiN2xdwnIRgl/N7ri5X9BKBfoRvpPohp08QQtI7XtfP W/e46j97Kr30Lojnq8+dasOmGR7rnOpvuKTcBLt5HTRjvNTMAWNLeKE0s6qRNQ6lQu62 LLM7e/2NKRLOONKgwwLBAE1T+poQlkfeEtWS/BiXrYMuGFw3D/NeIxPydDyuRscwvo0W CaxQ== X-Gm-Message-State: APjAAAUOGDriL/gfwtTr0vfCBw/Fnljr4/YN8jMsT5uVNrZHkEO9M6Bf PRttjWeil4LpulHnCgQQXt+SBurs X-Google-Smtp-Source: APXvYqzsc49tzaz5nWnkgqUYmMY4uogYsTBhxJmsZCjzZCIDWj10lSn1ZOHryQ+MUmWoKSkUpNyPvg== X-Received: by 2002:a5d:6144:: with SMTP id y4mr30197820wrt.367.1574891928859; Wed, 27 Nov 2019 13:58:48 -0800 (PST) Original-Received: from [192.168.0.5] ([212.50.117.215]) by smtp.googlemail.com with ESMTPSA id c9sm8028121wmb.42.2019.11.27.13.58.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 13:58:48 -0800 (PST) In-Reply-To: <01F6BECA-B48A-4B8F-BFBC-1FBED482864F@acm.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:172565 Archived-At: Hi Mattias, On 26.11.2019 21:32, Mattias EngdegÄrd wrote: > As it turned out, rx is fine (now); elixir-mode, not quite. In elixir-mode.el, we have > > (identifiers . ,(rx (one-or-more (any "A-Z" "a-z" "_")) > (zero-or-more (any "A-Z" "a-z" "0-9" "_")) > (optional (or "?" "!")))) > > First, this regex is suboptimal: the first character of an identifier should occur exactly once, or you get bad backtracking behaviour. Just remove the one-or-more construct: > > (identifiers . ,(rx (any "A-Z" "a-z" "_") > (zero-or-more (any "A-Z" "a-z" "0-9" "_")) > (optional (or "?" "!")))) > > This definition is then used in several places, but two in particular are of interest to us: > > ;; Module attributes > (,(elixir-rx (and "@" (1+ identifiers))) > > The construct (1+ identifiers) was perhaps meant to match multiple identifiers, but it doesn't (no separator); it just matches an identifier in several ways, which again leads to bad backtracking behaviour. > The same problem here: > > ;; Map keys > (,(elixir-rx (group (and (one-or-more identifiers) ":")) space) > > Remove the 1+ and one-or-more and it's fast again. That makes a lot of sense. I removed these one-or-more's and 1+ (and a few others), and it became fast again. I'll send a patch upstream. Thanks for your help! (Looking at the tracker, they have a minor version of this change submitted already). > Why did this "work" with the old rx implementation? Because that code had a nasty bug: it does not bracket definitions in rx-constituents properly. Example: > > (let ((rx-constituents (cons '(hello . "HELLO") rx-constituents))) > (rx-to-string '(1+ hello) t)) > => "HELLO+" > > The new rx implementation does not suffer from this bug. > > The result in your case is that the old rx, when translating (1+ identifiers), only tacked the "+" onto whatever regexp 'identifiers' produced, resulting in > > "[A-Z_a-z]+[0-9A-Z_a-z]*[!?]?+" > > which is a lot faster, since only the final [!?] is repeated twice (and it probably doesn't match very often). It's funny to think how someone probably beaten the current code into submission by trial and error.