Subject: bug#70108: 29.1.90; `defalias' and `current-load-list'

From: Stefan Monnier <[email-masked]>
Date: Mon, 01 Apr 2024 12:40:27 -0400

>> Duplicate entries sounds like a bug (unless there are two calls to
>> `defalias` for the same function name within the same file).
>> Do you have a reproducible recipe that shows this?
> That is exactly the scenario.  There's a setup function that gets
> called, which in turn sets up the defaliases.  Each test would then end
> up calling this setup function, which would result in the same file
> foo.el calling defalias multiple times for things it has already
> defined.

Ah, OK, so it sounds like a misfeature in your code which should
presumably avoid doing the setup repeatedly.
[ As opposed to the case where those "duplicate" definitions end up
  defining the functions differently.  ]

Good.  That means that you can easily work around the current
performance problem.

> Still, I find it a bit odd that it's *that* slow.

How slow are we talking about?
Have you tried `M-x profiler-start RET RET` and then later
`M-x profiler-report RET`?

In the absence of a reproducible recipe, I'd be interested to see where
the time is spent.

> We're talking hundreds, not millions, of entries.

You mentioned 600, so if there's the usual O(N²) behavior, that quickly
gets us to 100K territory which can be slow enough to be noticeable.

> As I mentioned earlier, I do not think it's a bug, but it caught me
> out, so I figured I'd at least ask.

It does sound like a performance bug, tho (triggered by an undesirable
behavior in your code).
We fixed a similar problem in `defvar` in the past.

>>>> This variable can easily get overrun with identical entries if the
>>>> inattentive programmer does not check if it is already bound.
>> Hmmm... I'm beginning to wonder: do your `defalias` happen while loading
>> a file, or do they happen more "dynamically"?
> The file is loaded once as part of the batch emacs process to run the
> tests, and unless there's some ert shenanigans I'm not familiar with,
> I do not think so.

But are the problematic `defalias` performed while loading the file
that defines the tests, or doing the execution of those tests.

That affects for example whether those function definitions end up
appearing in `load-history` as belonging to the file or belonging to
"unknown".

        Stefan