Skip to content

Commit 83b10b9

Browse files
authored
Add SnoopPrecompile workload (#3193)
On my machine, this cuts the TTFX of a simple workload (using the GLPK solver, which is not used here) from about 8.5s to about 3s.
1 parent a978323 commit 83b10b9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
99
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
1010
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1111
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
12+
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
1213
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1314

1415
[compat]
1516
MathOptInterface = "1.11"
1617
MutableArithmetics = "1"
1718
OrderedCollections = "1"
19+
SnoopPrecompile = "1"
1820
julia = "1.6"
1921

2022
[extras]

src/JuMP.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,30 @@ for sym in names(@__MODULE__; all = true)
807807
@eval export $sym
808808
end
809809

810+
using SnoopPrecompile
811+
812+
@precompile_all_calls begin
813+
# Because lots of the work is done by macros, and macros are expanded
814+
# at lowering time, not much of this would get precompiled without `@eval`
815+
@eval begin
816+
let
817+
model = Model(
818+
() -> MOI.Utilities.MockOptimizer(
819+
MOI.Utilities.UniversalFallback(
820+
MOI.Utilities.Model{Float64}(),
821+
),
822+
),
823+
)
824+
@variable(model, x >= 0)
825+
@variable(model, 0 <= y <= 3)
826+
@objective(model, Min, 12x + 20y)
827+
@constraint(model, c1, 6x + 8y >= 100)
828+
@constraint(model, c2, 7x + 12y >= 120)
829+
optimize!(model)
830+
end
831+
end
832+
end
833+
810834
include("precompile.jl")
811835
_precompile_()
812836

0 commit comments

Comments
 (0)