aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSpencer Baugh2025-05-01 14:27:30 -0400
committerStefan Monnier2025-05-23 21:41:14 -0400
commite5218df144203ff1b5da3d46b7579b6455008ee7 (patch)
tree6cc03eb8f47174497b065fd4748e04792c6e0042 /src
parentc8795767292caaaa3765ef6fffb12a7c0809d642 (diff)
downloademacs-e5218df144203ff1b5da3d46b7579b6455008ee7.tar.gz
emacs-e5218df144203ff1b5da3d46b7579b6455008ee7.zip
Add load-path-filter-function and use it to optimize loading
When there are many directories on load-path, the part of load which searches load-path can become very slow. By filtering load-path up front to only contain directories which are likely to contain the searched-for file, load becomes much faster. This can be set in early-init.el for maximum effect. * lisp/startup.el (load-path-filter--cache) (load-path-filter-cache-directory-files): Add. * src/lread.c (Fload): Call load-path-filter-function. (syms_of_lread): Add load-path-filter-function.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lread.c b/src/lread.c
index 98cda8316ac..ed481c19721 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1424,12 +1424,16 @@ Return t if the file exists and loads successfully. */)
1424 suffixes = CALLN (Fappend, suffixes, Vload_file_rep_suffixes); 1424 suffixes = CALLN (Fappend, suffixes, Vload_file_rep_suffixes);
1425 } 1425 }
1426 1426
1427 Lisp_Object load_path = Vload_path;
1428 if (FUNCTIONP (Vload_path_filter_function))
1429 load_path = calln (Vload_path_filter_function, load_path, file, suffixes);
1430
1427#if !defined USE_ANDROID_ASSETS 1431#if !defined USE_ANDROID_ASSETS
1428 fd = openp (Vload_path, file, suffixes, &found, Qnil, 1432 fd = openp (load_path, file, suffixes, &found, Qnil,
1429 load_prefer_newer, no_native, NULL); 1433 load_prefer_newer, no_native, NULL);
1430#else 1434#else
1431 asset = NULL; 1435 asset = NULL;
1432 rc = openp (Vload_path, file, suffixes, &found, Qnil, 1436 rc = openp (load_path, file, suffixes, &found, Qnil,
1433 load_prefer_newer, no_native, &asset); 1437 load_prefer_newer, no_native, &asset);
1434 fd.fd = rc; 1438 fd.fd = rc;
1435 fd.asset = asset; 1439 fd.asset = asset;
@@ -6107,6 +6111,18 @@ where FILE is the filename of the eln file, including the .eln extension.
6107through `require'. */); 6111through `require'. */);
6108 load_no_native = false; 6112 load_no_native = false;
6109 6113
6114 DEFVAR_LISP ("load-path-filter-function",
6115 Vload_path_filter_function,
6116 doc: /* Non-nil means to call this function to filter `load-path' for `load'.
6117
6118When load is called, this function is called with three arguments: the
6119current value of `load-path' (a list of directories), the FILE argument
6120to load, and the current load-suffixes.
6121
6122It should return a list of directories, which `load' will use instead of
6123`load-path'. */);
6124 Vload_path_filter_function = Qnil;
6125
6110 /* Vsource_directory was initialized in init_lread. */ 6126 /* Vsource_directory was initialized in init_lread. */
6111 6127
6112 DEFSYM (Qcurrent_load_list, "current-load-list"); 6128 DEFSYM (Qcurrent_load_list, "current-load-list");