GNU bug report logs - #78306
[PATCH] Skip the non-exists path when loading a file on Windows

Previous Next

Package: emacs;

Reported by: Lin Sun <sunlin7 <at> hotmail.com>

Date: Thu, 8 May 2025 00:25:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

To reply to this bug, email your comments to 78306 AT debbugs.gnu.org.
There is no need to reopen the bug first.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 00:25:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lin Sun <sunlin7 <at> hotmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 08 May 2025 00:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lin Sun <sunlin7 <at> hotmail.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] Skip the non-exists path when loading a file on Windows
Date: Thu, 8 May 2025 00:19:24 +0000
[Message part 1 (text/plain, inline)]
Emacs will searching file with a suffix even the dir is not exists.
For example, (add-to-list 'load-path "/path-not-exists"), then (require 'debug) will lead searching the debug.dll/debug.elc/debug.el under the "/path-not-exists" on windows.

This patch will distinguish the non-exists-dir to skip the unnecessary file operations.
[Message part 2 (text/html, inline)]
[0001-Skip-the-non-exists-path-when-loading-a-file-on-Wind.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 05:45:04 GMT) Full text and rfc822 format available.

Message #8 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lin Sun <sunlin7 <at> hotmail.com>
Cc: 78306 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file on
 Windows
Date: Thu, 08 May 2025 08:44:35 +0300
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Date: Thu, 8 May 2025 00:19:24 +0000
> 
> Emacs will searching file with a suffix even the dir is not exists.
> For example, (add-to-list 'load-path "/path-not-exists"), then (require 'debug) will lead searching the
> debug.dll/debug.elc/debug.el under the "/path-not-exists" on windows.
> 
> This patch will distinguish the non-exists-dir to skip the unnecessary file operations. 

Thanks, but I'm against this change.  faccessat is a general-purpose
function, so changing the errno it returns on Windows will affect a
lot of places in Emacs, with consequences we cannot predict.

If you want to skip directories that don't exist, or exist as files
that are non-directories, IMO the right way is to modify the loop in
openp such that in the following snippet:

  FOR_EACH_TAIL_SAFE (path)
   {
    ptrdiff_t baselen, prefixlen;

    if (EQ (path, just_use_str))
      filename = str;
    else
      filename = Fexpand_file_name (str, XCAR (path));
    if (!complete_filename_p (filename))
      /* If there are non-absolute elts in PATH (eg ".").  */
      /* Of course, this could conceivably lose if luser sets
	 default-directory to be something non-absolute...  */
      {
	filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
	if (!complete_filename_p (filename))
	  /* Give up on this path element!  */
	  continue;
      }

we verify that 'XCAR (path)' (and possibly also the current buffer's
default-directory') is an accessible directory, e.g. by using
file-accessible-directory-p.  This might benefit Posix platforms as
well, but we should benchmark the results before we decide.  (We
should also consider how likely it is that load-path will include
non-directories or directories that don't exist.)

Btw, did you benchmark the result of your proposed patch, and if so,
what is the speedup from this change?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 07:39:02 GMT) Full text and rfc822 format available.

Message #11 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Michael Albinus <michael.albinus <at> gmx.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Lin Sun <sunlin7 <at> hotmail.com>, 78306 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Thu, 08 May 2025 09:38:15 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

Hi,

> If you want to skip directories that don't exist, or exist as files
> that are non-directories, IMO the right way is to modify the loop in
> openp such that in the following snippet:
>
>   FOR_EACH_TAIL_SAFE (path)
>    {
>     ptrdiff_t baselen, prefixlen;
>
>     if (EQ (path, just_use_str))
>       filename = str;
>     else
>       filename = Fexpand_file_name (str, XCAR (path));
>     if (!complete_filename_p (filename))
>       /* If there are non-absolute elts in PATH (eg ".").  */
>       /* Of course, this could conceivably lose if luser sets
> 	 default-directory to be something non-absolute...  */
>       {
> 	filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
> 	if (!complete_filename_p (filename))
> 	  /* Give up on this path element!  */
> 	  continue;
>       }
>
> we verify that 'XCAR (path)' (and possibly also the current buffer's
> default-directory') is an accessible directory, e.g. by using
> file-accessible-directory-p.  This might benefit Posix platforms as
> well, but we should benchmark the results before we decide.  (We
> should also consider how likely it is that load-path will include
> non-directories or directories that don't exist.)
>
> Btw, did you benchmark the result of your proposed patch, and if so,
> what is the speedup from this change?

I don't know whether the snippet above is also relevant for remote
files. If yes, adding a call of file-accessible-directory-p might
influence performance.

Best regards, Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 08:47:02 GMT) Full text and rfc822 format available.

Message #14 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Albinus <michael.albinus <at> gmx.de>
Cc: sunlin7 <at> hotmail.com, 78306 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Thu, 08 May 2025 11:46:22 +0300
> From: Michael Albinus <michael.albinus <at> gmx.de>
> Cc: Lin Sun <sunlin7 <at> hotmail.com>,  78306 <at> debbugs.gnu.org,  Stefan Monnier
>  <monnier <at> iro.umontreal.ca>
> Date: Thu, 08 May 2025 09:38:15 +0200
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >   FOR_EACH_TAIL_SAFE (path)
> >    {
> >     ptrdiff_t baselen, prefixlen;
> >
> >     if (EQ (path, just_use_str))
> >       filename = str;
> >     else
> >       filename = Fexpand_file_name (str, XCAR (path));
> >     if (!complete_filename_p (filename))
> >       /* If there are non-absolute elts in PATH (eg ".").  */
> >       /* Of course, this could conceivably lose if luser sets
> > 	 default-directory to be something non-absolute...  */
> >       {
> > 	filename = Fexpand_file_name (filename, BVAR (current_buffer, directory));
> > 	if (!complete_filename_p (filename))
> > 	  /* Give up on this path element!  */
> > 	  continue;
> >       }
> >
> > we verify that 'XCAR (path)' (and possibly also the current buffer's
> > default-directory') is an accessible directory, e.g. by using
> > file-accessible-directory-p.  This might benefit Posix platforms as
> > well, but we should benchmark the results before we decide.  (We
> > should also consider how likely it is that load-path will include
> > non-directories or directories that don't exist.)
> >
> > Btw, did you benchmark the result of your proposed patch, and if so,
> > what is the speedup from this change?
> 
> I don't know whether the snippet above is also relevant for remote
> files. If yes, adding a call of file-accessible-directory-p might
> influence performance.

It could, yes.  In which case, depending on the speedups we measure in
local cases, we could only do this for local directories, or maybe
even only on MS-Windows.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 13:14:02 GMT) Full text and rfc822 format available.

Message #17 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Lin Sun <sunlin7 <at> hotmail.com>
Cc: 78306 <at> debbugs.gnu.org
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Thu, 08 May 2025 09:13:06 -0400
> Emacs will searching file with a suffix even the dir is not exists.

You don't say why you think it's a problem.  It's been doing that for
decades, and it's quite common to have a non-existing directory in
`load-path` (e.g. the `<ROOT>/share/emacs/<VERSION>/site-lisp` if you're
running Emacs "in place") yet it's never been seen as a problem.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Thu, 08 May 2025 14:47:01 GMT) Full text and rfc822 format available.

Message #20 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Lin Sun <sunlin7 <at> hotmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>, Eli Zaretskii <eliz <at> gnu.org>,
 Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "78306 <at> debbugs.gnu.org" <78306 <at> debbugs.gnu.org>
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Thu, 8 May 2025 14:46:42 +0000
Hi Eli, Stefan, Michael,

Thanks for all your comments that let me research more on this this patch, and the non-exists dir in path is not a bug, it do has risk on behavior changing, so this patch should not to be applied.   Removing non-exists dir from load-path is better way.


From: Eli Zaretskii <eliz <at> gnu.org>
Sent: Thursday, May 8, 2025 05:44 AM
> Thanks, but I'm against this change.  faccessat is a general-purpose
> function, so changing the errno it returns on Windows will affect a
> lot of places in Emacs, with consequences we cannot predict.

The errno was used on function file_directory_p after sys_faccessat for windows, other cases only use its return value. 

> If you want to skip directories that don't exist, or exist as files
> that are non-directories, IMO the right way is to modify the loop in
> openp such that in the following snippet:
....
> ... (We
> should also consider how likely it is that load-path will include
> non-directories or directories that don't exist.)

Yes, should check why non-exists dir in the load-path.

From: Michael Albinus <michael.albinus <at> gmx.de>
Sent: Thursday, May 8, 2025 07:38 AM
> I don't know whether the snippet above is also relevant for remote
> files. If yes, adding a call of file-accessible-directory-p might
> influence performance.

File related APIs on windows is slow, it will influence the perormance.


From: Stefan Monnier <monnier <at> iro.umontreal.ca>
Sent: Thursday, May 8, 2025 01:13 PM
> You don't say why you think it's a problem.  It's been doing that for
> decades, and it's quite common to have a non-existing directory in
> `load-path` (e.g. the `<ROOT>/share/emacs/<VERSION>/site-lisp` if you're
> running Emacs "in place") yet it's never been seen as a problem.

I use a emacs distribution which contains several non-exists dirs in the load-path, and I found the issue by investigate its performance; no bug related to this, just for performance concern. 


Please feel free to close this ticket. Thank you!



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Sat, 24 May 2025 08:48:02 GMT) Full text and rfc822 format available.

Message #23 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lin Sun <sunlin7 <at> hotmail.com>
Cc: michael_heerdegen <at> web.de, monnier <at> iro.umontreal.ca, 78306 <at> debbugs.gnu.org
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Sat, 24 May 2025 11:46:53 +0300
> From: Lin Sun <sunlin7 <at> hotmail.com>
> CC: "78306 <at> debbugs.gnu.org" <78306 <at> debbugs.gnu.org>
> Date: Thu, 8 May 2025 14:46:42 +0000
> 
> Hi Eli, Stefan, Michael,
> 
> Thanks for all your comments that let me research more on this this patch, and the non-exists dir in path is not a bug, it do has risk on behavior changing, so this patch should not to be applied.   Removing non-exists dir from load-path is better way.

Any progress with this?  Should we close this bug?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78306; Package emacs. (Sat, 24 May 2025 12:26:02 GMT) Full text and rfc822 format available.

Message #26 received at 78306 <at> debbugs.gnu.org (full text, mbox):

From: Lin Sun <sunlin7 <at> hotmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: michael_heerdegen <at> web.de, monnier <at> iro.umontreal.ca, 78306 <at> debbugs.gnu.org
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Sat, 24 May 2025 05:25:27 -0700
[Message part 1 (text/html, inline)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 24 May 2025 13:09:02 GMT) Full text and rfc822 format available.

Notification sent to Lin Sun <sunlin7 <at> hotmail.com>:
bug acknowledged by developer. (Sat, 24 May 2025 13:09:03 GMT) Full text and rfc822 format available.

Message #31 received at 78306-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lin Sun <sunlin7 <at> hotmail.com>
Cc: michael_heerdegen <at> web.de, monnier <at> iro.umontreal.ca,
 78306-done <at> debbugs.gnu.org
Subject: Re: bug#78306: [PATCH] Skip the non-exists path when loading a file
 on Windows
Date: Sat, 24 May 2025 16:08:25 +0300
> Date: Sat, 24 May 2025 05:25:27 -0700
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Cc: monnier <at> iro.umontreal.ca, michael_heerdegen <at> web.de,
>  78306 <at> debbugs.gnu.org
> 
> On May 24, 2025 1:46 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>  Any progress with this?  Should we close this bug? 
> 
> One non-existing dir will be used during boot startup, no harmful there; and on my local, several non-existing
> dirs were added into load path by an external package management, I created a PR for it.
> 
> Please feel free to close this ticket, thank you.

Thanks, done.




This bug report was last modified 11 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.