-
Notifications
You must be signed in to change notification settings - Fork 5
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
Reduce CLI latency #1942
Comments
If we don't use the precompile file in PackageCompiler, the build is 6 minutes faster and only 6 MB smaller (than 313 MB) but the latency is about twice as high. Testing a simple PrecompileTools workload like using PrecompileTools: @compile_workload
@compile_workload begin
main(normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml"))
end seems to suffer from similar issues. It still compiles a lot of code when running other models. The function config.snake_case(nt::NodeType.T)::Symbol
if nt == NodeType.Basin
return :basin
elseif nt == NodeType.TabulatedRatingCurve
return :tabulated_rating_curve
elseif nt == NodeType.Pump
return :pump
elseif nt == NodeType.Outlet
return :outlet
elseif nt == NodeType.UserDemand
return :user_demand
elseif nt == NodeType.FlowDemand
return :flow_demand
elseif nt == NodeType.LevelDemand
return :level_demand
elseif nt == NodeType.FlowBoundary
return :flow_boundary
elseif nt == NodeType.LevelBoundary
return :level_boundary
elseif nt == NodeType.LinearResistance
return :linear_resistance
elseif nt == NodeType.ManningResistance
return :manning_resistance
elseif nt == NodeType.Terminal
return :terminal
elseif nt == NodeType.DiscreteControl
return :discrete_control
elseif nt == NodeType.ContinuousControl
return :continuous_control
elseif nt == NodeType.PidControl
return :pid_control
else
error("Unknown node type: $nt")
end
end |
I think #2091 would help here. Although benchmarking #2077 did not seem to make much of a difference, so it is probably not enough. Rather than focusing on precompilation we should first look why, after running test model A from a REPL, it still needs to compile so much code when running test model B after that. (Running A again after is fast) What code does it need to compile? ComponentArrays is one of them, but not sure what the situation is with OrdinaryDiffEq and JuMP. We probably need to use SnoopCompile. |
Everytime Ribasim needed to be recompiled and Makie was available we had to spend considerable time recompiling this extension. We avoid having to pay this price by moving it to `utils/plot.jl` instead. ```julia using Ribasim m = Ribasim.run("ribasim.toml") include("../utils/plot.jl") using CairoMakie plot_basin_data(m) ``` Helps latency #1942 and we should check if this helps with #2015 (edit: it doesn't). CairoMakie is still in our root Manifest.toml since we use it in our docs.
We can also try using |
In a REPL the
trivial
test model runs in about 0.03 seconds on the second run, but 20 seconds with the CLI. We put a lot of effort into making the solver fast to run. Little effort has been spent to quickly start a simulation. Users running thetrivial
test model from the CLI (v2024.11) need to wait 20 seconds each time. For short simulations or quick tests this hinders the iteration speed of modelers. Here is the output of hyperfine ontrivial
:Especially on a warm filesystem cache the loading of the binary is quick,
Info: Starting a Ribasim simulation
appears quickly. It then takes about 10 seconds forSimulating 0%
to appear, and another 10 seconds for the simulation to finish.That indicates that it still needs to compile a lot of code during a CLI run. Ten seconds worth of initialization / validation code and ten seconds of simulation code. I hoped that https://github.com/Deltares/Ribasim/blob/v2024.11.0/build/precompile.jl would precompile more of what we need, but apparently it doesn't. We can consider looking into this with SnoopCompile.jl. Right now we don't yet use PrecompileTools.jl in Ribasim.jl. We could start doing this as well.
I assume in time having small binaries with
juliac
will also help here.One way to completely avoid this issue is to run
Ribasim.main("ribasim.toml")
from Julia instead. If we'd support some way in the CLI to run multiple model (separate TOMLs) with one command this would similarly avoid the latency when doing multiple runs each time. It may be good to support separate TOMLs also for #47.The text was updated successfully, but these errors were encountered: