From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Is Elisp really that slow? Date: Mon, 13 May 2019 08:37:29 -0400 Message-ID: References: <20190502214006.4fdsinp7u5xuqvdv@Ergus> <20190503004416.xfuzzucflp6bxpuz@Ergus> <8736lm30lz.fsf@web.de> <864l61j04d.fsf@zoho.eu> <20190511073254.GB29829@tuxteam.de> <04187AB9-AD7D-492D-A890-BCB01848370C@icloud.com> <20190511075712.GD29829@tuxteam.de> <86a7fsfv1m.fsf@zoho.eu> <20190512075448.GA11650@tuxteam.de> <346107E9-590D-4A18-9152-ECFF36FC4EDC@icloud.com> <83r293bvok.fsf@gnu.org> <87ef53vihw.fsf@telefonica.net> <83mujrbsk7.fsf@gnu.org> <87a7frvfo1.fsf@telefonica.net> <83h89zbndc.fsf@gnu.org> <875zqfv7sb.fsf@telefonica.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="91568"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Samuel Wales Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 13 14:40:06 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQAFR-000NkZ-Nb for geh-help-gnu-emacs@m.gmane.org; Mon, 13 May 2019 14:40:06 +0200 Original-Received: from localhost ([127.0.0.1]:56631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQAFQ-0004yp-Mw for geh-help-gnu-emacs@m.gmane.org; Mon, 13 May 2019 08:40:04 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQAD6-0003S3-DO for help-gnu-emacs@gnu.org; Mon, 13 May 2019 08:37:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQAD4-00048h-Jh for help-gnu-emacs@gnu.org; Mon, 13 May 2019 08:37:40 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:51949) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hQAD2-00047f-NU for help-gnu-emacs@gnu.org; Mon, 13 May 2019 08:37:38 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 91B5944228D; Mon, 13 May 2019 08:37:35 -0400 (EDT) Original-Received: from mail02.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3B91044163A; Mon, 13 May 2019 08:37:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1557751050; bh=/tYF4QNB2mYMRZKAaZBTAHtiKX9TXJUw0Ir7oyp2slc=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Loz8O8ccWsEPbIn6LM0gYAeeeu8nLwdzu8jEDMOL8BrNgxHTqTOZjcq1Awe7Y6XX0 sJArO+5t9pz29a6wUqtDC+BdC8ehRiTm/+zkajPte3Kaa5UUERuvoucjciQdIjj5Wd 0tinSGDKtSvllmYyqqpuE0QfRcNxrBKrbPv1Jn/GwS3E4DOlLI3Z4XUMsh5+iqOVsg P9tNkZmPWOm4WD9I2snhclwF2OpPtb9Ws/i0gK8K4sHe32lbF/3A20gk0rhMoL/o2s a9/S0F6dCKqv6Wc9oZvLSn1qcGnGCmWbGgstqUfYwVqP/Q9bWZC+Rv1CxWUS23L2q0 Vbir0QVCk2sew== Original-Received: from pastel (69-196-155-191.dsl.teksavvy.com [69.196.155.191]) by mail02.iro.umontreal.ca (Postfix) with ESMTPSA id 0E405120155; Mon, 13 May 2019 08:37:30 -0400 (EDT) In-Reply-To: (Samuel Wales's message of "Sun, 12 May 2019 17:57:19 -0700") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120341 Archived-At: > can this be sped up? > > (while (re-search-forward from nil t) > (replace-match to t)) That's a perfect example where no matter how many man-years you invest into a super-duper fancy compiler for Elisp, the above code will not be affected one bit, because all the time is normally spent within `re-search-forward` and `replace-match` which are already implemented in C. As for whether it can be sped up: yes, no doubt it can. But how to speed it up will depend on `from`, on the density of matches in the text, and on the current major-mode, mostly (the complexity of `from` impacts the amount of time spent in re-search-forward and which approaches can reduce it, while the major-mode impacts the overhead of modifying the buffer (via before/after-change-functions)). I'd expect that in most cases, there won't be many matches so most of the time is spent in re-search-forward. This is already pretty fast in the case where the pattern is simple, but if the pattern is complex, our regexp-engine can be somewhere between not very efficient and pathologically slow. Fixing this would be great (even better if we can do it by re-using an existing regexp implementation), especially if we can do it without slowing down the simple case too much. Stefan