From f43ecbfbb6dbabac579e1b6b6883ea2a8c7f9a27 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Tue, 20 Aug 2024 10:45:41 +0200 Subject: [PATCH] Make Distributed support a package extension This shaves off ~180ms from loading, though it does require Julia 1.9+. --- Project.toml | 11 +++++++++-- .../DistributedExt.jl | 11 ++++++----- src/AbbreviatedStackTraces.jl | 1 - 3 files changed, 15 insertions(+), 8 deletions(-) rename src/override-Distributed-process_messages.jl => ext/DistributedExt.jl (77%) diff --git a/Project.toml b/Project.toml index c627570..02ad14c 100644 --- a/Project.toml +++ b/Project.toml @@ -4,11 +4,18 @@ authors = ["Nicholas Bauer "] version = "0.2.3" [deps] -Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +[weakdeps] +Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[extensions] +DistributedExt = ["Distributed"] + [compat] -julia = "1.6" +Distributed = "1" +REPL = "1" +julia = "1.9" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/override-Distributed-process_messages.jl b/ext/DistributedExt.jl similarity index 77% rename from src/override-Distributed-process_messages.jl rename to ext/DistributedExt.jl index 7ebd43e..cef86e5 100644 --- a/src/override-Distributed-process_messages.jl +++ b/ext/DistributedExt.jl @@ -1,14 +1,15 @@ -__precompile__(false) +module DistributedExt -import Base: - showerror +__precompile__(false) import Distributed: myid, RemoteException # copied from Distributed/process_messages.jl and added dealing with RemoteException -function showerror(io::IO, re::RemoteException) +function Base.showerror(io::IO, re::RemoteException) (re.pid != myid()) && print(io, "On worker ", re.pid, ":\n") showerror(IOContext(io, :compacttrace => false), re.captured) -end \ No newline at end of file +end + +end diff --git a/src/AbbreviatedStackTraces.jl b/src/AbbreviatedStackTraces.jl index 704440b..554cedb 100644 --- a/src/AbbreviatedStackTraces.jl +++ b/src/AbbreviatedStackTraces.jl @@ -7,7 +7,6 @@ include("override-errorshow.jl") include("override-show.jl") include("override-stacktraces.jl") include("override-REPL.jl") -include("override-Distributed-process_messages.jl") import Base: printstyled,