Skip to content

Commit e10e728

Browse files
Merge pull request #577 from ChrisRackauckas-Claude/precompile-improvements-20260101-033127
Add PrecompileTools workload to improve TTFX
2 parents 1d53e33 + 4be48b2 commit e10e728

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1212
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
1313
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1414
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
15+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1516
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
1617
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1718
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -33,6 +34,7 @@ MLUtils = "0.3, 0.4"
3334
ModelingToolkit = "11"
3435
OrdinaryDiffEqTsit5 = "1"
3536
Parameters = "0.12"
37+
PrecompileTools = "1"
3638
ProgressMeter = "1.6"
3739
QuadGK = "2.4"
3840
RecipesBase = "1"

src/DataDrivenDiffEq.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,7 @@ export get_algorithm, get_results, get_basis, is_converged, get_problem
145145
include("./utils/plot_recipes.jl")
146146
include("./utils/build_basis.jl")
147147

148+
# Precompilation workload to improve startup time and TTFX
149+
include("./precompilation.jl")
150+
148151
end # module

src/precompilation.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Precompilation workload for DataDrivenDiffEq
2+
# This file contains code that will be executed during precompilation to
3+
# improve startup time and time-to-first-execution (TTFX)
4+
5+
using PrecompileTools
6+
7+
@setup_workload begin
8+
# Set up minimal test data and variables
9+
# Note: We avoid heavy computations here, just trigger code paths
10+
@compile_workload begin
11+
# Create symbolic variables for Basis construction
12+
# This is the main TTFX bottleneck (33+ seconds without precompilation)
13+
@variables x y t
14+
15+
# Precompile Basis construction - the most important operation
16+
# Use simple expressions to minimize precompilation time
17+
basis = Basis([x, y, x * y, x^2, y^2], [x, y])
18+
19+
# Precompile basis evaluation (both scalar and vector forms)
20+
u_test = [1.0, 2.0]
21+
p_test = Float64[]
22+
t_test = 0.0
23+
_ = basis(u_test, p_test, t_test)
24+
25+
# Precompile problem constructors
26+
X = randn(2, 10)
27+
Y = randn(2, 10)
28+
t_span = collect(range(0.0, 1.0, length = 10))
29+
30+
# DirectDataDrivenProblem
31+
prob_direct = DirectDataDrivenProblem(X, Y)
32+
33+
# DiscreteDataDrivenProblem
34+
prob_discrete = DiscreteDataDrivenProblem(X)
35+
36+
# ContinuousDataDrivenProblem (uses collocation which takes time)
37+
prob_cont = ContinuousDataDrivenProblem(X, t_span)
38+
39+
# Precompile basis generators
40+
poly_basis = polynomial_basis([x, y], 2)
41+
mono_basis = monomial_basis([x, y], 2)
42+
43+
# Precompile basis evaluation with problem
44+
_ = basis(prob_direct)
45+
end
46+
end

0 commit comments

Comments
 (0)