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

Experimental: precompile functions #531

Closed
wants to merge 1 commit into from
Closed

Experimental: precompile functions #531

wants to merge 1 commit into from

Conversation

IainNZ
Copy link
Collaborator

@IainNZ IainNZ commented Aug 14, 2015

Test script:

start_t = time_ns()
println("start ", (time_ns()-start_t)/10^9); start_t = time_ns()
using JuMP
println("using ", (time_ns()-start_t)/10^9); start_t = time_ns()
m = Model()
println("model ", (time_ns()-start_t)/10^9); start_t = time_ns()
N=10000
@defVar(m, x[1:N])
println("defva ", (time_ns()-start_t)/10^9); start_t = time_ns()
@addConstraint(m, sum{i*x[i],i=1:N} >= N)
println("addcn ", (time_ns()-start_t)/10^9); start_t = time_ns()

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 14, 2015

Seems to help way more in global scope than in a function, not sure why.

@joehuchette
Copy link
Contributor

I'm pretty sure the printing code takes forever to compile; what happens if you precompile some of that? Or use ; in global scope...

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 14, 2015

Yeah printing takes forever, that was gonna my next challenge if this worked at all.

To be clear, I was running that code as a script (with precompiled JuMP), so its not doing any printing (I also run with coverage to identity what was running).

Most of the benefit came from the addToExpression_reorder, the rest from the parse* methods. The others didn't do anything as far as I can tell.

Base.precompile(buildrefsets, (Expr,))
# parseExpr_staged.jl
Base.precompile(addToExpression_reorder, (AffExpr,(Int,Variable)))
Base.precompile(addToExpression_reorder, (AffExpr,(Float64,Int)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are v0.4 only

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@joehuchette
Copy link
Contributor

Cool, looks like it's helping a lot with the constraint

@@ -1015,6 +1015,8 @@ include("callbacks.jl")
include("print.jl")
# Nonlinear-specific code
include("nlp.jl")
# Precompile functions to speed up initial runs
include("precompile.jl")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional include on VERSION > v"0.4-"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge this, yeah

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 15, 2015

@iaindunning: have you measured a benefit to doing that? unless you use it in sysimg/userimg, precompile doesn't actually save machine code.

slackbot [11:51 PM] 
spell-check "precompile": did you mean "magic"?

----- Today August 15th, 2015 -----

iaindunning [12:24 AM] 
@ihnorton: I'm seeing something

iaindunning [12:24 AM]
https://github.com/JuliaOpt/JuMP.jl/pull/531

GitHub
Experimental: precompile functions by IainNZ · Pull Request #531 · JuliaOpt/JuMP.jl · GitHub
Test script: start_t = time_ns() println("start ", (time_ns()-start_t)/10^9); start_t = time_ns() using JuMP println("using ", (time_ns()-start_t)/10^9); start_t = time_ns() m = Model() println("m...

iaindunning [12:24 AM]
i don't know how to explain it, if thats the case

iaindunning [12:24 AM]
maybe something to do with the generation function

ihnorton [12:29 AM] 
ah, yeah... with so much code generation that makes sense as precompiling should save you the fully expanded versions of everything

ihnorton [12:29 AM]
in lowered form

iaindunning [12:29 AM] 
the timing change was non-trivial, like 2x for the thing i was focused on

iaindunning [12:29 AM]
ahhh ok

iaindunning [12:29 AM]
so code with not involving macros would not likely see the benefit?

ihnorton [12:31 AM] 
jameson was talking about it earlier this evening and said (IIUC) that the benefit was minimal in the code he had profiled, but I think that was inference (which does a lot of things, but thankfully doesn't use @generated yet)

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 18, 2015

I was looking around and saw that PyCall was exploring similar ideas (JuliaPy/PyCall.jl#167)

@IainNZ
Copy link
Collaborator Author

IainNZ commented Aug 24, 2015

Closing in favour of #541

@IainNZ IainNZ closed this Aug 24, 2015
@IainNZ IainNZ deleted the precompilefunc branch August 24, 2015 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants