# Slow runtime when assigning struct reference

**URL:** <https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713>\
**Category:** New to Julia\
**Created:** [October 1, 2018, 1:32am UTC](https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713 "2018-10-01T01:32:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_A](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@Chris\_A](https://discourse.julialang.org/u/Chris_A)\
**Post date:** [October 1, 2018, 1:32am UTC](https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713/1 "2018-10-01T01:32:03Z")

</div>

Fair warning to anyone reading this: Mechanical engineer here, leave your sensibilities at the door.

I’m playing around with building a finite volume code in Julia and am having trouble when trying to assign references to my mesh (a larger struct containing cell/face data) inside another struct designed to hold values for the cells/faces

Basically what I have is the following:

> mutable struct mesh\_format  
> id::Int64  
> nodes::Vector{node\_format}  
> faces::Vector{face\_format}  
> cells::Vector{cell\_format}  
> end
> 
> mutable struct mesh\_var  
> #reference to the mesh  
> mesh::mesh\_format  
> #arrays for the faces, cells  
> cellVals::Vector{Float64}  
> faceVals::Vector{Float64}  
> end

mesh\_format holds the geometry of the mesh and mesh\_var holds the actual values and reference to the mesh for operations that need to know geometric data.

My first test case isn’t super obscene, 4800 cells and 9760 faces. The issue arises when I try to assign reference to mesh\_var.mesh in a constructor or elsewhere in my code. When I do so the execution seems to stall, or at least take a very long time to run. If I make the assignment in the console it occurs within seconds, which I expect as this should just be a pointer to the mesh. Am I missing something here?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 1, 2018, 1:40am UTC](https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713/2 "2018-10-01T01:40:04Z")

</div>

Without an example that could be run, it is hard to say much.

---

<div class="post-metadata">

**Author:** ![Chris\_A](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@Chris\_A](https://discourse.julialang.org/u/Chris_A)\
**Post date:** [October 1, 2018, 2:02am UTC](https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713/3 "2018-10-01T02:02:45Z")

</div>

Fixed this (just after I posed it, isn’t that always the case)

Solution was to add a simple operation as the last line of the script i was trying to run, rather than leave it being assignment to a mesh\_var or something of the like.

I THINK its because of this:  
I think Juno (which I was using) suppresses output from running a script but doesn’t really? Looks like Julia was trying to output my last variable, which included reference to the mesh and also included circular references so it was taking forever to ‘output’ but not actually outputting (Juno still suppresses this somewhere along the way I guess though since nothing ends up on the console out?)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 1, 2018, 12:16pm UTC](https://discourse.julialang.org/t/slow-runtime-when-assigning-struct-reference/15713/4 "2018-10-01T12:16:17Z")

</div>

please quote your code and provide a self-contained MWE

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
