Skip to content

Commit 5e1083c

Browse files
authored
Speed up dlpath() on MacOS (#35630)
`dlpath()` on MacOS iterated over all loaded image names, calling `dlopen()` on them again and comparing returned handles to see if the given handle matched. This wasted a lot of time running through the `dlopen()` machinery, we can bypass much of it by passing `RTLD_NOLOAD` in to `dlopen()`, as we are assured that all pathnames we are probing are already loaded.
1 parent 5819223 commit 5e1083c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/sys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ JL_DLLEXPORT const char *jl_pathname_for_handle(void *handle)
532532
for (int32_t i = _dyld_image_count() - 1; i >= 0 ; i--) {
533533
// dlopen() each image, check handle
534534
const char *image_name = _dyld_get_image_name(i);
535-
void *probe_lib = jl_load_dynamic_library(image_name, JL_RTLD_DEFAULT, 0);
535+
void *probe_lib = jl_load_dynamic_library(image_name, JL_RTLD_DEFAULT | JL_RTLD_NOLOAD, 0);
536536
jl_dlclose(probe_lib);
537537

538538
// If the handle is the same as what was passed in (modulo mode bits), return this image name

0 commit comments

Comments
 (0)