# Improve performance of a code with very large % of Garbage Collection

**URL:** <https://discourse.julialang.org/t/improve-performance-of-a-code-with-very-large-of-garbage-collection/75548>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, performance, garbage-collection, nlopt\
**Created:** [January 31, 2022, 10:28pm UTC](https://discourse.julialang.org/t/improve-performance-of-a-code-with-very-large-of-garbage-collection/75548 "2022-01-31T22:28:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 1, 2022, 12:37am UTC](https://discourse.julialang.org/t/improve-performance-of-a-code-with-very-large-of-garbage-collection/75548/2 "2022-02-01T00:37:36Z")

</div>

Just to clarify:

- You want to optimize using NLopt:
  - A function `myfunc_floops`
    - That calls `f1` which repeatedly calls `f2`
      - Which formulates and solves an optimization model using Mosek.

That’s going to involve a lot of calls to `f1`, which creates and destroys a lot of JuMP models. That’s the reason for your GC issue.

As recommended here:

> [@Performance of Computation of Expectation of slow function](https://discourse.julialang.org/t/performance-of-computation-of-expectation-of-slow-function/74961):
>
> Hi! I am trying to optimize this section of code. Basically, there are two functions. The first one solves a linear programming problem over a convex set. The second function computes a Monte Carlo experiment over S trials of the first function. I can see how the second function can be easy to parallelize, however, this tidbit is part of a larger loop which I am parallelizing. Any help would be very much appreciated!! using JuMP, LinearAlgebra, Random, Distributions, BenchmarkTools, MosekTools …

did you try creating a single JuMP model and calling `fix` on it?

Have you tried creating a single large JuMP model instead of the loop over `z[:,s]`? You could potentially find all solutions for `Simul` simultaneously a single large Mosek model.

---

_[View the full topic](https://discourse.julialang.org/t/improve-performance-of-a-code-with-very-large-of-garbage-collection/75548)._
