From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#64735: 29.0.92; find invocations are ~15x slower because of ignores Date: Tue, 12 Sep 2023 19:32:41 +0300 Message-ID: <831qf3pd1y.fsf@gnu.org> References: <83sf9eub9d.fsf@gnu.org> <2d844a34-857d-3d59-b897-73372baac480@gutov.dev> <83bkg2tsu6.fsf@gnu.org> <83bd4246-ac41-90ec-1df3-02d0bd59ca44@gutov.dev> <834jlttv1p.fsf@gnu.org> <937c3b8e-7742-91b7-c2cf-4cadd0782f0c@gutov.dev> <83a5vlsanw.fsf@gnu.org> <69a98e2a-5816-d36b-9d04-8609291333cd@gutov.dev> <87351cs8no.fsf@localhost> <35163e56-607d-9c5b-e3e8-5d5b548b3cb7@gutov.dev> <878rb3m43b.fsf@localhost> <83v8e6lyi4.fsf@gnu.org> <35f8b664-0241-9f96-1aa0-20ca51b2d34c@gutov.dev> <59c30342-a7e0-d83b-a128-0faae4cbd633@gutov.dev> <83pm4bi6qa.fsf@gnu.org> <83bkfs2tw5.fsf@gnu.org> <18a0b4d8-32bd-3ecd-8db4-32608a1ebba7@gutov.dev> <83il8lxjcu.fsf@gnu.org> <2e21ec81-8e4f-4c02-ea15-43bd6da3daa7@gutov.dev> <8334zmtwwi.fsf@gnu.org> <83tts0rkh5.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11820"; mail-complaints-to="usenet@ciao.gmane.io" Cc: luangruo@yahoo.com, sbaugh@janestreet.com, yantar92@posteo.net, 64735@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 12 18:34:13 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qg6L7-0002tp-6w for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Sep 2023 18:34:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qg6Ku-0007HH-D4; Tue, 12 Sep 2023 12:34:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg6Ks-0007Gv-F9 for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 12:33:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qg6Ks-0000Sd-4E for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 12:33:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qg6Kw-00056f-Al for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 12:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Sep 2023 16:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64735 X-GNU-PR-Package: emacs Original-Received: via spool by 64735-submit@debbugs.gnu.org id=B64735.169453639219569 (code B ref 64735); Tue, 12 Sep 2023 16:34:02 +0000 Original-Received: (at 64735) by debbugs.gnu.org; 12 Sep 2023 16:33:12 +0000 Original-Received: from localhost ([127.0.0.1]:59864 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qg6K7-00055Z-VZ for submit@debbugs.gnu.org; Tue, 12 Sep 2023 12:33:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qg6K3-00055I-MB for 64735@debbugs.gnu.org; Tue, 12 Sep 2023 12:33:10 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qg6Js-0007xZ-9R; Tue, 12 Sep 2023 12:32:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=VZwx7DhGquSA4ytEqqiIcDZjXhsS4uUJ1h0/YBNoRXM=; b=Tsc1X9aST/DO QIAxsu/o3H/W4q3JkVNIL7Ci38gMm/VYHYJ3XA0a9rT8RsCcIxO5TtIYB54Zuggfuy0b6oUvqwnr0 JuLec/i6QKwQdEE6p/DpSgW13BsVZ+CWCpQe/+byCkoifOoqW8juKkfIKvjWdezLwWne7/8EUE746 /wrMbwzKDHsPVDr+CuosAe4dnWb+xbTKGI2wC5YxRhKD3Xoxt6DSwaBX2jcykB/fpDN/4xoQ2wGIo XwwtuO4r4Qvq4UZDcxDzHWgoDVQwsv+e+xIjXCOnW4RQhOxQnWVkRf4NzByaMOJhggiRcMDx3bvT/ a3RWAbFIzRpk48Z+NFpslQ==; In-Reply-To: (message from Dmitry Gutov on Tue, 12 Sep 2023 17:23:53 +0300) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:270193 Archived-At: > Date: Tue, 12 Sep 2023 17:23:53 +0300 > Cc: luangruo@yahoo.com, sbaugh@janestreet.com, yantar92@posteo.net, > 64735@debbugs.gnu.org > From: Dmitry Gutov > > - Dropping most of the setup in read_and_dispose_of_process_output > (which creates some consing too) and calling > Finternal_default_process_filter directly (call_filter_directly.diff), > when it is the filter to be used anyway. > > - Going around that function entirely, skipping the creation of a Lisp > string (CHARS -> TEXT) and inserting into the buffer directly (when the > filter is set to the default, of course). Copied and adapted some code > from 'call_process' for that (read_and_insert_process_output.diff). > > Neither are intended as complete proposals, but here are some > comparisons. Note that either of these patches could only help the > implementations that don't set up process filter (the naive first one, > and the new parallel number 5 above). > > For testing, I used two different repo checkouts that are large enough > to not finish too quickly: gecko-dev and torvalds-linux. > > master > > | Function | gecko-dev | linux | > | find-directory-files-recursively | 1.69 | 0.41 | > | find-directory-files-recursively-2 | 1.16 | 0.28 | > | find-directory-files-recursively-3 | 0.92 | 0.23 | > | find-directory-files-recursively-5 | 1.07 | 0.26 | > | find-directory-files-recursively (rpom 409600) | 1.42 | 0.35 | > | find-directory-files-recursively-2 (rpom 409600) | 0.90 | 0.25 | > | find-directory-files-recursively-5 (rpom 409600) | 0.89 | 0.24 | > > call_filter_directly.diff (basically, not much difference) > > | Function | gecko-dev | linux | > | find-directory-files-recursively | 1.64 | 0.38 | > | find-directory-files-recursively-5 | 1.05 | 0.26 | > | find-directory-files-recursively (rpom 409600) | 1.42 | 0.36 | > | find-directory-files-recursively-5 (rpom 409600) | 0.91 | 0.25 | > > read_and_insert_process_output.diff (noticeable differences) > > | Function | gecko-dev | linux | > | find-directory-files-recursively | 1.30 | 0.34 | > | find-directory-files-recursively-5 | 1.03 | 0.25 | > | find-directory-files-recursively (rpom 409600) | 1.20 | 0.35 | > | find-directory-files-recursively-5 (rpom 409600) | (!!) 0.72 | 0.21 | > > So it seems like we have at least two potential ways to implement an > asynchronous file listing routine that is as fast or faster than the > synchronous one (if only thanks to starting the parsing in parallel). > > Combining the last patch together with using the very large value of > read-process-output-max seems to yield the most benefit, but I'm not > sure if it's appropriate to just raise that value in our code, though. > > Thoughts? I'm not sure what exactly is here to think about. Removing portions of read_and_insert_process_output, or bypassing it entirely, is not going to fly, because AFAIU it basically means we don't decode text, which can only work with plain ASCII file names, and/or don't move the markers in the process buffer, which also cannot be avoided. If you want to conclude that inserting the process's output into a buffer without consing Lisp strings is faster (which I'm not sure, see below, but it could be true), then we could try extending internal-default-process-filter (or writing a new filter function similar to it) so that it inserts the stuff into the gap and then uses decode_coding_gap, which converts inserted bytes in-place -- that, at least, will be correct and will avoid consing intermediate temporary strings from the process output, then decoding them, then inserting them. Other than that, the -2 and -3 variants are very close runners-up of -5, so maybe I'm missing something, but I see no reason be too excited here? I mean, 0.89 vs 0.92? really? About inserting into the buffer: what we do is insert into the gap, and when the gap becomes full, we enlarge it. Enlarging the gap involves: (a) enlarging the chunk of memory allocated to buffer text (which might mean we ask the OS for more memory), and (b) moving the characters after the gap to the right to free space for inserting more stuff. This is pretty fast, but still, with a large pipe buffer and a lot of output, we do this many times, so it could add up to something pretty tangible. It's hard to me to tell whether this is significantly faster than consing strings and inserting them, only measurements can tell.