# Optimizing Large-Scale Problems: One Large Problem vs. Multiple Smaller Ones

**URL:** https://discourse.julialang.org/t/optimizing-large-scale-problems-one-large-problem-vs-multiple-smaller-ones/129711
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [June 6, 2025, 6:37pm UTC](https://discourse.julialang.org/t/optimizing-large-scale-problems-one-large-problem-vs-multiple-smaller-ones/129711 "2025-06-06T18:37:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![fdekerme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fdekerme/32/43574_2.png) [@fdekerme](https://discourse.julialang.org/u/fdekerme)
#### Post date: [June 6, 2025, 6:37pm UTC](https://discourse.julialang.org/t/optimizing-large-scale-problems-one-large-problem-vs-multiple-smaller-ones/129711/1 "2025-06-06T18:37:08Z")

</div>

Hello 😀,  
By reading [this example](https://docs.sciml.ai/NonlinearSolve/stable/basics/faq/) of NonlinearSolve.jl, I was asking myself if it was better to define large-scale optimization problem as 1 large problem (`f2`) or several small problems (`f1`).

According to the code below, the `f2` version is much slower, because (?) the `Vector` version of `myfunc` is not allocation-free.

Is it the only reason and is there good practice in this situation (one large problem vs several smaller)?

```julia
using NonlinearSolve, BenchmarkTools

const Nt = 100;
levels = 1.5 .* rand(Nt);
out = zeros(Nt);
myfun(x::Number, lv::Number) = x * sin(x) - lv
myfun(x::Vector, lv::Vector) = x .* sin.(x) .- lv

function f1(out, levels, u0)
    for i in 1:Nt
        out[i] = solve(
            NonlinearProblem{false}(NonlinearFunction{false}(myfun), u0, levels[i]),
            SimpleNewtonRaphson()).u
    end
end

function f2(levels, u0)
        solve(
            NonlinearProblem{false}(NonlinearFunction{false}(myfun), u0, levels),
            SimpleNewtonRaphson()).u
end

@btime f1(out, levels, 1.0)
@btime f2(levels, ones(Nt))

```

Thanks,  
fdekerm

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 6, 2025, 6:50pm UTC](https://discourse.julialang.org/t/optimizing-large-scale-problems-one-large-problem-vs-multiple-smaller-ones/129711/2 "2025-06-06T18:50:46Z")

</div>

Pretty much. You should use SimpleNonlinearSolve.jl with static arrays if it’s small and it should be fully non allocating
