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

module init functions #1268

Closed
JeffBezanson opened this issue Sep 8, 2012 · 7 comments
Closed

module init functions #1268

JeffBezanson opened this issue Sep 8, 2012 · 7 comments
Assignees
Milestone

Comments

@JeffBezanson
Copy link
Member

It is common for C libraries to require some init call on startup, like Tk_Init. It would be nice to know about modules that need to call such functions, and hook them into julia's _init in the future when julia code is used as a library.

Currently we have 2 overall phases: definition time (when a source file is loaded) and run time. We need to insert "startup time" in between. It takes place right after load time when you first load a file, and also at startup when "compiled" code is loaded.

@timholy
Copy link
Member

timholy commented Feb 16, 2014

Much less important than module initialization, but possibly worth including in the thought process here: an optional thunk for forced-precompilation. See https://github.com/timholy/Images.jl/blob/2d51289829a74aeeaa18bd93e3532f6fe32eb5a0/src/Images.jl#L24-L49

I was able to reduce the time to load Images and run the algorithms.jl test to about 40% of its former value, yay!

@StefanKarpinski
Copy link
Member

So how does that help the load time? Wouldn't it just shift around when the compilation happens? Why is it better to do all the precompilation up front than on demand?

@timholy
Copy link
Member

timholy commented Feb 16, 2014

It doesn't change the load time (using Images is now blazingly fast either way), but if I put Images.precompile() into my userimg.jl, then those functions get precompiled when I build Julia. So it increases the amount of time needed to build Julia, but it makes it faster to start computing things on each launch. Assuming that building Julia is less frequent than using Julia, it's a win.

@StefanKarpinski
Copy link
Member

Ah, yes, I see. That makes perfect sense. We should definitely support that.

@JeffBezanson JeffBezanson modified the milestones: 0.3, 1.0 Feb 17, 2014
@JeffBezanson
Copy link
Member Author

My straw man proposal here would be to call a function named _init() in a module, if it exists, when the module is loaded. However, I immediately wonder if this should be more general, and let you attach initializers (somewhat like finalizers) to objects or types. This could be used for

  1. Specifying how to initialize a particular module (the original issue here)
  2. Rehashing ObjectIdDicts (currently a special case)
  3. Restoring native pointers for e.g. Regex

@timholy
Copy link
Member

timholy commented Feb 18, 2014

Under what other circumstances would you have to attach initializers to objects besides module initialization?

@JeffBezanson
Copy link
Member Author

Yeah, we might be better off not over-engineering this and just adding simple module init functions. After all you can use those to set up arbitrary data structures anyway.

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

3 participants