unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Eli Zaretskii <eliz@gnu.org>
Cc: pot@gnu.org, 73484@debbugs.gnu.org, spwhitton@spwhitton.name
Subject: bug#73484: 31.0.50; Abolishing etags-regen-file-extensions
Date: Wed, 9 Oct 2024 21:23:37 +0300	[thread overview]
Message-ID: <3e63f532-c6af-4923-880b-01a32cc667ec@gutov.dev> (raw)
In-Reply-To: <86ploasq35.fsf@gnu.org>

On 08/10/2024 16:04, Eli Zaretskii wrote:

>>>> I think that option will be useful, but for better benchmarks and for
>>>> end usability as well, I think we need the N^2 thing fixed as well.
>>>> Maybe before the rest of the changes.
>>>
>>> If this latter part is a precodintion,
>>
>> I think we still could use the new flag, just not switch to it (no
>> extension filtering) by default yet.
> 
> OK, installed on master.  I leave it up to you whether to close the
> bug.

Thank you!

Before closing though, I'd like to look into the performance issue more.

>>> then someone else will have to
>>> work on this.  I have the new option coded and tested (and
>>> documented), but I don't intend to work on redesigning the core etags
>>> algorithms to remove the non-linear behavior, that's a much larger
>>> project which I currently cannot afford, sorry.
>>
>> Do you mind pointing at the places in the code where you already noticed
>> non-linear performance coming from?
> 
> The while-loop near line 2020, for example.

Thanks. This one must be proportional to the number of files such as 
*.y. There are only 2 in our big repo.

> Another one is the for-loop near line 1420, which deals with writing
> into TAGS the entries of files with no tags.

It's not a nested 'for' loop, though (right?), and it's called from 
'main'. That seems to mean it's just O(N) - also fine.

> There may be others, but those are what I saw.  Perhaps it is a good
> idea to profile etags while it scans the files during those 15 min, to
> see where it spends that much time, because I'm not sure even those
> loops can account for that.  It's possible there's something else at
> work here which we don't yet understand.

'perf' shows me a profile like this:

   67.31%  etags    libc.so.6          [.] __strcmp_avx2
   26.29%  etags    etags              [.] process_file_name
    2.00%  etags    etags              [.] streq
    0.96%  etags    etags              [.] strcmp@plt
    0.32%  etags    etags              [.] readline_internal
    0.11%  etags    etags              [.] HTML_labels
    0.08%  etags    [kernel.kallsyms]  [k] syscall_return_via_sysret
    0.07%  etags    [kernel.kallsyms]  [k] kmem_cache_alloc
    0.06%  etags    [kernel.kallsyms]  [k] entry_SYSRETQ_unsafe_stack
    0.05%  etags    [kernel.kallsyms]  [k] perf_adjust_freq_unthr_context
    0.04%  etags    etags              [.] c_strncasecmp

So... most of the time is spent in string comparison.

Here is the nested loop, which if I comment out, makes the parse finish 
in ~20 seconds, with all the extra files (except *.js), or in 15s when 
using with new flags.

diff --git a/lib-src/etags.c b/lib-src/etags.c
index a822a823a90..331e3ffe816 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -1697,14 +1697,14 @@ process_file_name (char *file, language *lang)
        uncompressed_name = file;
      }

-  /* If the canonicalized uncompressed name
-     has already been dealt with, skip it silently. */
-  for (fdp = fdhead; fdp != NULL; fdp = fdp->next)
-    {
-      assert (fdp->infname != NULL);
-      if (streq (uncompressed_name, fdp->infname))
-	goto cleanup;
-    }
+  /* /\* If the canonicalized uncompressed name */
+  /*    has already been dealt with, skip it silently. *\/ */
+  /* for (fdp = fdhead; fdp != NULL; fdp = fdp->next) */
+  /*   { */
+  /*     assert (fdp->infname != NULL); */
+  /*     if (streq (uncompressed_name, fdp->infname)) */
+  /* 	goto cleanup; */
+  /*   } */

    inf = fopen (file, "r" FOPEN_BINARY);
    if (inf)

This is basically a "uniqueness" operation using linear search, O(N^2).

Is there a hash table we could use?

Or perhaps we would skip the search when the canonicalized name is the 
same as the original one.

> Two aspects that I found trying to understand the long scan times, and
> I'd like to mention so they don't become forgotten:
> 
>   . If there are compressed files in the directory, etags will
>     uncompress them before it attempts to identify their language.
>     There are 20 such files in the gecko-dev tree (removing them from
>     the list of scanned files had only minor effect on the elapsed
>     time, but it could be different in other cases, especially if
>     uncompressing them produces very large files).

I guess someone might ask for flag "--no-decompress", sometime.

>   . Some files have their language identified by means other than their
>     names or extensions: those are the languages that have
>     "interpreters" defined in etags.c.  Shell scripts is one such case,
>     but not the only one.  So when etags-regen.el passes only files
>     with known extensions to etags, it misses those files from TAGS.
>     As one example, the file js/src/devtools/rootAnalysis/run_complete
>     in the gecko-dev tree is a Perl script, but has no .pl extension.

This sounds the same as the "hashbang" files that we mentioned 
previously. It makes sense for the scan to take longer, of course, 
proportional to the number of the detected files.





  reply	other threads:[~2024-10-09 18:23 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87tteaznog.fsf@zephyr.silentflame.com>
     [not found] ` <edab570c-b2fa-4162-9383-df5c8aaff251@yandex.ru>
     [not found]   ` <8734lrrj4e.fsf@zephyr.silentflame.com>
     [not found]     ` <ea10f340-9b46-4199-93fc-274c5e81ace4@yandex.ru>
     [not found]       ` <87o74c1ce1.fsf@zephyr.silentflame.com>
     [not found]         ` <b8001a72-8fc9-4e4e-a2d7-5da94a92f250@yandex.ru>
2024-09-25 19:27           ` bug#73484: 31.0.50; Abolishing etags-regen-file-extensions Sean Whitton
2024-09-25 22:30             ` Dmitry Gutov
2024-09-26  7:43               ` Francesco Potortì
2024-09-26 12:18                 ` Dmitry Gutov
2024-09-29  8:25               ` Eli Zaretskii
2024-09-29 10:56                 ` Eli Zaretskii
2024-09-29 17:15                   ` Francesco Potortì
2024-09-30 23:19                 ` Dmitry Gutov
2024-10-01 15:00                   ` Eli Zaretskii
2024-10-01 22:01                     ` Dmitry Gutov
2024-10-02 11:28                   ` Eli Zaretskii
2024-10-02 18:00                     ` Dmitry Gutov
2024-10-02 18:56                       ` Eli Zaretskii
2024-10-02 22:03                         ` Dmitry Gutov
2024-10-03  6:27                           ` Eli Zaretskii
2024-10-04  1:25                             ` Dmitry Gutov
2024-10-04  6:45                               ` Eli Zaretskii
2024-10-04 23:01                                 ` Dmitry Gutov
2024-10-05  7:02                                   ` Eli Zaretskii
2024-10-05 14:29                                     ` Dmitry Gutov
2024-10-05 15:27                                       ` Eli Zaretskii
2024-10-05 20:27                                         ` Dmitry Gutov
2024-10-05 16:38                                       ` Francesco Potortì
2024-10-05 17:12                                         ` Eli Zaretskii
2024-10-06  0:56                                         ` Dmitry Gutov
2024-10-06  6:22                                           ` Eli Zaretskii
2024-10-06 19:14                                             ` Dmitry Gutov
2024-10-07  2:33                                               ` Eli Zaretskii
2024-10-07  7:11                                                 ` Dmitry Gutov
2024-10-07 16:05                                                   ` Eli Zaretskii
2024-10-07 17:36                                                     ` Dmitry Gutov
2024-10-07 19:05                                                       ` Eli Zaretskii
2024-10-07 22:08                                                         ` Dmitry Gutov
2024-10-08 13:04                                                           ` Eli Zaretskii
2024-10-09 18:23                                                             ` Dmitry Gutov [this message]
2024-10-09 19:11                                                               ` Eli Zaretskii
2024-10-09 22:22                                                                 ` Dmitry Gutov
2024-10-10  5:13                                                                   ` Eli Zaretskii
2024-10-10  1:07                                                               ` Francesco Potortì
2024-10-10  5:41                                                                 ` Eli Zaretskii
2024-10-10  8:27                                                                   ` Francesco Potortì
2024-10-10  8:35                                                                     ` Eli Zaretskii
2024-10-10 14:25                                                                       ` Francesco Potortì
2024-10-10 16:28                                                                         ` Eli Zaretskii
2024-10-11 10:37                                                                           ` Francesco Potortì
2024-10-10 10:17                                                                 ` Dmitry Gutov
2024-10-10  1:39                                                               ` Francesco Potortì
2024-10-10  5:45                                                                 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e63f532-c6af-4923-880b-01a32cc667ec@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=73484@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=pot@gnu.org \
    --cc=spwhitton@spwhitton.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).