-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid __init__
to reduce load time
#340
Comments
Hmm, good to know. In the short term we can probably push this code down into either the init for the AD systems that need it, or perhaps into ChainRules.jl. Which we only have to allow ADs to do because it let's them generate code for rule overloads that use generic dispatch. Do you know how much of the load time is from having and |
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
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
Removing this might be argued to be breaking. So I think we can remove it as nonbreaking, and revert if someone says it breaks their code. How much of a rush are you for this? |
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
Thinking a bit more about this, is there any reason these hooks need to be added by ChainRulesCore? Perhaps we can move these hooks to ChainRules or even its own small package, so they are only added, when they are actually required by an AD. |
Very low :P, I've just started measuring some package load times based on some complaints and now filing issues / PRs wherever it seems reasonable. |
We can almost definitely remove the attaching a package load hook in the init. Edit: |
Yes, please push as much as possible into a separate package. The only things in ChainRulesCore, in my mind, should be the functions necessary to define new differentiation rules — it should as lightweight as possible to make a no-brainer to add differentiability to any package. |
I have created https://github.com/JuliaDiff/ChainRulesOverloadGeneration.jl to push out the overload generation to (Right now it just has a slice out of the history of this repo pruned down to just contain the relevent files, but I will fix up names and make it work after) |
ChainRulesCore causes significant load time regressions in packages that depend on it (e.g. JuliaMath/SpecialFunctions.jl#310). A significant amount of that is contributed to the
__init__
function that unconditionally has to be run when the package is loaded since this has to be inferred and compiled.Removing the
__init__
reduces approximately cuts the load time of the package to a factor of 1/3. If this package is supposed to be dependent on by such core packages as SpecialFunctions it would be good if its goals could be achieved with standard dispatch which the package loading system is optimized for, instead of running arbitrary code at load time.The text was updated successfully, but these errors were encountered: