Background
I'm optimizing using servers, and have a custom object called Cell that has objects in PhysicsServer and VisualServer attached to it. The Cell has an instance in the VisualServer that has a SphereMesh
(documentation) as its mesh, and the body and areas have SphereShape
s (documentation) as their shapes. A summary of the definition in the Cell class:
# VISUAL
visualinstance = VisualServer.instance_create()
visualmesh = SphereMesh.new()
VisualServer.instance_set_base(visualinstance, visualmesh)
# AREAs
contact_area = PhysicsServer.area_create()
contact_area_shape = SphereShape.new()
PhysicsServer.area_add_shape( contact_area, contact_area_shape, ... )
transmission_area = PhysicsServer.area_create()
transmission_area_shape = SphereShape.new()
PhysicsServer.area_add_shape( transmission_area, transmission_area_shape, ... )
# PHYSICS
body = PhysicsServer.body_create()
body_shape = SphereShape.new()
PhysicsServer.body_add_shape(body, body_shape)
where ( , ...) means that there is additional code that I'm omitting since I don't think it relevant to the question.
Question
Now to the question. When running, I have a function that sets the radius of the Cell, for example as it grows or when it divides, that I've defined either like this:
func set_cell_radius_example_1(new_body_radius:float):
body_shape.radius = new_body_radius
visualmesh.radius = new_body_radius
visualmesh.height = new_body_radius*2
contact_area_shape.radius = new_body_radius*3
transmission_area_shape.radius = new_body_radius*4
or like this:
func set_cell_radius_example_2(new_body_radius:float):
body_shape.set_radius(new_body_radius)
visualmesh.set_radius(new_body_radius)
visualmesh.set_height(new_body_radius*2)
contact_area_shape.set_radius(new_body_radius*3)
transmission_area_shape.set_radius(new_body_radius*4)
For both definitions of set_cell_radius
, they seem to be taking a surprisingly long time to execute when analyzed using the debugger profiler. Here's an screenshot of the Profiler output:

that shows that the set_cell_radius
functions take on average 4,5 milliseconds to execute. This seems very high to me since it simply sets five parameters.
Why is this the case? Are my intuitions wrong and this is "normal"? Or am I doing something wrong...?