module init functions #1268

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

Comments

Projects
None yet
3 participants
@JeffBezanson
Member

JeffBezanson commented Sep 8, 2012

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

This comment has been minimized.

Show comment
Hide comment
@timholy

timholy Feb 16, 2014

Member

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!

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

This comment has been minimized.

Show comment
Hide comment
@StefanKarpinski

StefanKarpinski Feb 16, 2014

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?

Member

StefanKarpinski commented Feb 16, 2014

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

This comment has been minimized.

Show comment
Hide comment
@timholy

timholy Feb 16, 2014

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@StefanKarpinski

StefanKarpinski Feb 16, 2014

Member

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

Member

StefanKarpinski commented Feb 16, 2014

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

This comment has been minimized.

Show comment
Hide comment
@JeffBezanson

JeffBezanson Feb 18, 2014

Member

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
Member

JeffBezanson commented Feb 18, 2014

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

This comment has been minimized.

Show comment
Hide comment
@timholy

timholy Feb 18, 2014

Member

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

Member

timholy commented Feb 18, 2014

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

@JeffBezanson

This comment has been minimized.

Show comment
Hide comment
@JeffBezanson

JeffBezanson Feb 18, 2014

Member

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.

Member

JeffBezanson commented Feb 18, 2014

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