From f3939cc19dca9ce39495e335fec6a7f897e30bec Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sun, 2 May 2021 18:06:10 +0200 Subject: [PATCH 1/3] precompile package callback With this PR: ``` (ChainRulesCore) pkg> precompile Precompiling project... 1 dependency successfully precompiled in 2 seconds (1 already precompiled) julia> @time using ChainRulesCore 0.082255 seconds (157.13 k allocations: 9.737 MiB, 5.59% compilation time) ``` Before: ``` julia> @time using ChainRulesCore 0.111551 seconds (443.47 k allocations: 25.618 MiB, 3.87% compilation time) ``` Removing the hook alltogether: ``` julia> @time using ChainRulesCore 0.033357 seconds (36.37 k allocations: 2.399 MiB, 17.75% compilation time) ``` That's still more overhead than I'd like, so we should still discuss whether we could avoid these hooks, but it does at least improve the current situation somewhat. Ref #340 --- src/ruleset_loading.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ruleset_loading.jl b/src/ruleset_loading.jl index 2b8b91cea..218bba3aa 100644 --- a/src/ruleset_loading.jl +++ b/src/ruleset_loading.jl @@ -1,7 +1,8 @@ # Infastructure to support generating overloads from rules. +_package_hook(::Base.PkgId) = refresh_rules() function __init__() # Need to refresh rules when a package is loaded - push!(Base.package_callbacks, pkgid -> refresh_rules()) + push!(Base.package_callbacks, _package_hook) end # Holds all the hook functions that are invokes when a new rule is defined @@ -139,3 +140,5 @@ function _safe_hook_fun(hook_fun, sig) @error "Error triggering hook" hook_fun sig exception=(err, catch_backtrace()) end end + +precompile(_package_hook, (Base.PkgId,)) From 0f826a3fc61cb9b99ea246e9bb913fdfbcf604bd Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sun, 2 May 2021 18:35:59 +0200 Subject: [PATCH 2/3] move precompile statement to its own file --- src/ChainRulesCore.jl | 2 ++ src/precompile.jl | 1 + src/ruleset_loading.jl | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 src/precompile.jl diff --git a/src/ChainRulesCore.jl b/src/ChainRulesCore.jl index 35ff8ffe1..48c2be9e4 100644 --- a/src/ChainRulesCore.jl +++ b/src/ChainRulesCore.jl @@ -30,4 +30,6 @@ include("rules.jl") include("rule_definition_tools.jl") include("ruleset_loading.jl") +include("precompile.jl") + end # module diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 000000000..ba4e72c8d --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1 @@ +precompile(_package_hook, (Base.PkgId,)) diff --git a/src/ruleset_loading.jl b/src/ruleset_loading.jl index 218bba3aa..aa40fae26 100644 --- a/src/ruleset_loading.jl +++ b/src/ruleset_loading.jl @@ -140,5 +140,3 @@ function _safe_hook_fun(hook_fun, sig) @error "Error triggering hook" hook_fun sig exception=(err, catch_backtrace()) end end - -precompile(_package_hook, (Base.PkgId,)) From bea0985f130fad7ca869d5d0bc0fede2aff881cc Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sun, 2 May 2021 18:37:23 +0200 Subject: [PATCH 3/3] bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1ff522a82..af3b030ab 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ChainRulesCore" uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" -version = "0.9.40" +version = "0.9.41" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"