From 86cc2303a1a3201f56f9a960c2fa71a60b83be39 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 17 Oct 2021 06:35:07 -0500 Subject: [PATCH 1/2] Dict->IdDict in exception types Dicts use extensive specialization and this adds latency. IdDicts don't and are the go-to associative container for type-keys. --- src/exception.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exception.jl b/src/exception.jl index 7df89269..5b609a83 100644 --- a/src/exception.jl +++ b/src/exception.jl @@ -140,7 +140,7 @@ end ######################################################################### # Mapping of Julia Exception types to Python exceptions -const pyexc = Dict{DataType, PyPtr}() +const pyexc = IdDict{DataType, PyPtr}() mutable struct PyIOError <: Exception end function pyexc_initialize() From 146c1ecfc72bab346a284751b65dfb08a59e11c0 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sun, 17 Oct 2021 06:55:13 -0500 Subject: [PATCH 2/2] Rely on `const` to solve inference problems The `::Dict`, being an abstract annotation, wouldn't have been all that much help anyway. --- src/exception.jl | 2 +- src/io.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exception.jl b/src/exception.jl index 5b609a83..362719ed 100644 --- a/src/exception.jl +++ b/src/exception.jl @@ -213,7 +213,7 @@ end function pyraise(e, bt = nothing) eT = typeof(e) - pyeT = haskey(pyexc::Dict, eT) ? pyexc[eT] : pyexc[Exception] + pyeT = haskey(pyexc, eT) ? pyexc[eT] : pyexc[Exception] err = PyJlError(e, bt) ccall((@pysym :PyErr_SetObject), Cvoid, (PyPtr, PyPtr), pyeT, PyObject(err)) diff --git a/src/io.jl b/src/io.jl index 145b2fea..bee8440f 100644 --- a/src/io.jl +++ b/src/io.jl @@ -11,7 +11,7 @@ function ioraise(e, bt = nothing) if isa(e, MethodError) || isa(e, ErrorException) ccall((@pysym :PyErr_SetString), Cvoid, (PyPtr, Cstring), - (pyexc::Dict)[PyIOError], + pyexc[PyIOError], showerror_string(e, bt)) else pyraise(e, bt)