Skip to content
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

A lazier approach to precompilation #358

Closed
ghost opened this issue Apr 20, 2023 · 3 comments
Closed

A lazier approach to precompilation #358

ghost opened this issue Apr 20, 2023 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 20, 2023

Having dedicated precompile statements is fine for libraries, but not ideal for applications.
What if function calls could be precompiled when they are called? "just in time precompilation"

Let's say there is a macro

@precompile_on_demand f(...)

That wraps the call in a separate module, precompiles that module, and replaces the call with the call from that module?

module PrecompMod
@precompile_all_calls f(...)
end
using .PrecompMod
PrecompMod.f(...)

maybe this can be done with Cassette?

@timholy
Copy link
Owner

timholy commented Apr 20, 2023

I'm not certain I understand the points you are making.

Having dedicated precompile statements is fine for libraries, but not ideal for applications.

Are you talking about workload-based precompilation with SnoopPrecompile, or explicit precompile(f, argtypes) directives? And what specifically about applications makes this harder? Are you aware of https://julialang.github.io/Precompiler.jl/dev/#Tutorial:-local-%22Startup%22-packages (which is written for what will become SnoopPrecompile's successor, but fully applicable if you replace names like Precompiler in those docs with their current SnoopPrecompile counterparts).

What if function calls could be precompiled when they are called? "just in time precompilation"

They are already: any time you execute foo(args...), if this combination of types has never been compiled before, it will be compiled before it runs. But you have to wait until compilation finishes before the function starts running. Are you proposing something that would be done ahead of time?

@ghost
Copy link
Author

ghost commented Apr 20, 2023

Are you talking about workload-based precompilation with SnoopPrecompile, or explicit precompile(f, argtypes) directives?

I am thinking of, for example, cli applications where there might be many combinations of flags, and maybe precompiling all the combinations would be too much

Are you proposing something that would be done ahead of time?

Like running a cli command with some flags. The next time it runs with those same flags it would use a precompiled version, so I am referring to persistent precompilation like it is done for packages, but now that I think about it precompilation happens at package level, not a module level, so what I wrote is gibberish :)

@timholy
Copy link
Owner

timholy commented Apr 20, 2023

Gotcha. I think for a cli application, one would do the flag-processing at runtime, so I think it would probably be quite feasible to compile the code that implements the different options. (You only need one compile target, not one target per combination of flags.)

I'll close this, but if you play with this and come up with a concrete example of something that isn't working as you might hope, happy to talk about fixes!

@timholy timholy closed this as completed Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant