Passing object vs passing variables

Posted on
Thu Dec 22, 2016 9:58 am
bkmar1192 offline
Posts: 274
Joined: Sep 12, 2015

Passing object vs passing variables

Amateur programmer question.

My plugin is pretty CPU intensive and I am trying to find ways to improve performance.

In my plugin I call several subroutines for each device. Each of those subroutines gets state and attribute settings from the device.

Is it more efficient to pass the device object to the subroutine or get my variables in the main loop and pass a series of 5 or 6 strings.

Thanks for the help.


Sent from my iPhone using Tapatalk

Posted on
Thu Dec 22, 2016 10:43 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Passing object vs passing variables

Passing the device object to the subroutines is probably cleaner, but I doubt there's a significant CPU penalty either way.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Dec 22, 2016 1:00 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Passing object vs passing variables

Agreed – passing either the entire device instance or the variables will be about the same. One thing you don't want is to do multiple device look-ups. These are all examples of a device lookup which will cause an Indigo Server call:

dev = indigo.devices[123]
dev = indigo.devices["some dev name"]
brightness = indigo.devices[123].brightness
foo = indigo.devices[123].pluginProps["foo"]

In cases like that it is best to get the device once, then use that instance for access to all attributes of the device.

Image

Posted on
Thu Dec 22, 2016 3:12 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Passing object vs passing variables

Just keep in mind that the copy of the device instance you get is static. It won't update if the device changes. You'll need to get it again to get updated values.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Dec 23, 2016 11:22 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Passing object vs passing variables

Or refresh it:

Code: Select all
dev.refreshFromServer()

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Dec 23, 2016 2:20 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Passing object vs passing variables

jay (support) wrote:
Or refresh it:

Code: Select all
dev.refreshFromServer()


Is this significantly more efficient than just getting a new copy?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests