# Dynamic reloading of Objects using Revise or Cassette?

**URL:** https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018
**Category:** General Usage
**Created:** [April 22, 2020, 9:21am UTC](https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018 "2020-04-22T09:21:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [April 22, 2020, 9:21am UTC](https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018/1 "2020-04-22T09:21:03Z")

</div>

Hello all,

I need help to find a strategy to speed up my development process. I have written a framework in Julia, which I use for writing conversational agents.

Whenever I am working on the framework code, everything is painless and automatic, thanks to Revise (execpt the ocassional struct redefinition).

However, when I am working on client-code, I have to reload everything, which can be very expensive (an agent potentially includes a lot of modules, read some TOML files and transform this into objects). I will try to put an abstract example:

```julia
agent_x = AgentXModule.agent
agent_y = AgentXModule.agent
agent_z = AgentXModule.agent

agent_selector = Framework.AgentSelector(
 agentX = agent_x,
 agentY = agent_Y,
 agentZ = agent_Z,
)

```

And then:

```julia
answer(agent_selector, input) 

```

Each agent has a structure similar to this:

```julia
/agent_x
  /scenarios/
   |_ scenario_1.toml
  /modules/
   |_ scenario_1.jl

```

And is defined in a module like this:

```julia
module AgentX
using Framework
include("agents/x/modules/scenario_1.jl")

agent = Framework.AgentXExpensiveInstantiation(...)

end

```

What I would like to do is to observer those `modules` and `scenarios` folder so when one changes, the corresponding `Agent` is partially updated as wells as `AgentSelector` with the new `Agent` version.

Is this feasible with `Revise.jl` or `Cassette.jl`? Does someone have any experience with a similar problem or can provide any guidance?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [April 22, 2020, 5:15pm UTC](https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018/2 "2020-04-22T17:15:14Z")

</div>

IIUC [`Revise.entr`](https://timholy.github.io/Revise.jl/stable/user_reference/#Revise.entr) could help you there (see also the paragraph about [“Other Revise workflows”](https://timholy.github.io/Revise.jl/stable/#Other-Revise-workflows-1) in the documentation).

So you’d have something like

```julia
entr(["agent_x/scenarios/scenario_1.toml"], # Watch for changes in scenarios
     [AgentX]) do # or in the code defining package AgentX (including scenario_1.jl)
    AgentX.update() # Put in this function anything that AgentX needs to do
    Framework.update(:AgentX) # maybe the Framework needs some updating too...
end

```

---

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [May 11, 2020, 7:49am UTC](https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018/3 "2020-05-11T07:49:44Z")

</div>

Hey, @ffevotte, thank you for your answer and sorry for the late reply, how rude of me. Some other things took priority at work and I completely forgot about this.

I had taken a look to `Revise.entr`, but hand’t found a workable solution. I think what you propose could be already an improvement. However, ideally `Revise.entr` would be able to detect which specific file changed (I would watch not only an scenario but probably a dozen or two) and make more granular uupdates. I don’t know if this is possible, though.

I will be working on this today and see if I find something that works. Thank you for your help!

---

<div class="post-metadata">

### Author: ![Amval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amval/32/6217_2.png) [@Amval](https://discourse.julialang.org/u/Amval)
#### Post date: [May 11, 2020, 4:20pm UTC](https://discourse.julialang.org/t/dynamic-reloading-of-objects-using-revise-or-cassette/38018/4 "2020-05-11T16:20:04Z")

</div>

Actually, it seems like the `Revise.entr` approach doesn’t work for me (because I would need to include modules inside the loop to make the update, and that doesn’t seem to work).

Fortunately, I found a performance bottleneck that was causing very slow instantiation and that I can ignore while in development. Time went down like 90+%.
