If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
RUBY: Droplist selector uses massive CPU when copied
18 posts
• Page 2 of 2 • 1, 2
Re: RUBY: Droplist selector uses massive CPU when copied
Another step!
If I make 3 copies I get high cpu. BUT, if I change to the topmost front panel view, the cpu drops to zero. See the attached.
This doesn’t further my understanding really, but it’s interesting to find. I made some similar tests using other Ruby-based modules but I don’t get the same behaviour. I can have many Ruby knobs or keyboards inside a module but the static cpu doesn’t increase when I view them.
Cheers
Spogg
If I make 3 copies I get high cpu. BUT, if I change to the topmost front panel view, the cpu drops to zero. See the attached.
This doesn’t further my understanding really, but it’s interesting to find. I made some similar tests using other Ruby-based modules but I don’t get the same behaviour. I can have many Ruby knobs or keyboards inside a module but the static cpu doesn’t increase when I view them.
Cheers
Spogg
- Attachments
-
- Ruby dropbox with very high cpu dev 4 .fsm
- (44.15 KiB) Downloaded 883 times
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: RUBY: Droplist selector uses massive CPU when copied
Maybe the final step…
I tested this in the current X64 and 32 bit beta versions of Flowstone and there is no problem. CPU usage is “zero” for all situations.
So, while I honestly don’t understand what’s going on, it’ll be gone in the forthcoming Flowstone 4 release.
Like tulamide said, there has been Ruby development for the next version, so my conclusion must be that the issue relates somehow to the createDropList method, since that’s the only thing unique to this module.
So it’s back to my actual fun project now
Thanks for all the input guys.
Spogg
I tested this in the current X64 and 32 bit beta versions of Flowstone and there is no problem. CPU usage is “zero” for all situations.
So, while I honestly don’t understand what’s going on, it’ll be gone in the forthcoming Flowstone 4 release.
Like tulamide said, there has been Ruby development for the next version, so my conclusion must be that the issue relates somehow to the createDropList method, since that’s the only thing unique to this module.
So it’s back to my actual fun project now
Thanks for all the input guys.
Spogg
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: RUBY: Droplist selector uses massive CPU when copied
This is what I'm referring to.
But the two lines above it also doesn't belong into a drawing method, since they create anarray from a string and evaluate one of the created values. That's all time consuming, when several redraws take place. The method is called "draw" for a reason
But the two lines above it also doesn't belong into a drawing method, since they create anarray from a string and evaluate one of the created values. That's all time consuming, when several redraws take place. The method is called "draw" for a reason
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: RUBY: Droplist selector uses massive CPU when copied
Thank you SO much tulamide!
I do believe I actually understand this now
I’ve re-worked the RubyEdit and all seems well now, but maybe you or someone else could have a look to see if there’s anything else stupid remaining.
This has been a great learning experience for me so, again, thanks to all for joining in.
Spogg
I do believe I actually understand this now
I’ve re-worked the RubyEdit and all seems well now, but maybe you or someone else could have a look to see if there’s anything else stupid remaining.
This has been a great learning experience for me so, again, thanks to all for joining in.
Spogg
- Attachments
-
- Ruby dropbox with very high cpu dev 5 .fsm
- FIXED!!
- (28.04 KiB) Downloaded 912 times
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: RUBY: Droplist selector uses massive CPU when copied
Nicely done
I couldn't spot any more issues from the code. There is still a good part of optimization possible, but nothing drastically. For example, you could define all the pens and brushes as class instance variables in the init method. This will save a little bit cpu load, but more importantly doesn't claim and release so much memory. Instead of doing it per draw call, it is only done once at the beginning. This will reduce the load to the gc (garbage collector), that has to take care of releasing classes and variables that aren't used anymore, which is a time consuming process.
For your understanding:
a = 2 + 4 -> gc gets notified about a variable referring to 6
...some time passes
gc checks if variable is still in use. If not, it will release the memory asociated with the it.
Let's assume 'a' is still alive, as this code is executed:
a = "Word"
gc gets notified that 'a' now references a string. It marks '6' as to be released and at the next collection process it will be released.
In the real code the pens and brushes are assigned to a variable everytime a drawing takes place. Each time also the gc is informed about the variables pointing to a newly created class, which makes it mandatory to release the memory of the previous classes, that are now not needed anymore. The more redraws, the more work for the gc. With my proposal this relation is broken, since all variables will point to one place in memory each, which won't ever change through runtime = no work for the gc = saved a lot of time.
I couldn't spot any more issues from the code. There is still a good part of optimization possible, but nothing drastically. For example, you could define all the pens and brushes as class instance variables in the init method. This will save a little bit cpu load, but more importantly doesn't claim and release so much memory. Instead of doing it per draw call, it is only done once at the beginning. This will reduce the load to the gc (garbage collector), that has to take care of releasing classes and variables that aren't used anymore, which is a time consuming process.
For your understanding:
a = 2 + 4 -> gc gets notified about a variable referring to 6
...some time passes
gc checks if variable is still in use. If not, it will release the memory asociated with the it.
Let's assume 'a' is still alive, as this code is executed:
a = "Word"
gc gets notified that 'a' now references a string. It marks '6' as to be released and at the next collection process it will be released.
In the real code the pens and brushes are assigned to a variable everytime a drawing takes place. Each time also the gc is informed about the variables pointing to a newly created class, which makes it mandatory to release the memory of the previous classes, that are now not needed anymore. The more redraws, the more work for the gc. With my proposal this relation is broken, since all variables will point to one place in memory each, which won't ever change through runtime = no work for the gc = saved a lot of time.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: RUBY: Droplist selector uses massive CPU when copied
Fascinating!
I’ve not tried to implement this but it leads me to a question:
If a brush or pen colour is changed external to the RubyEdit (as in my example) would this be picked up if it had been defined in the init method?
I understood the init method was only called at start-up, or when there was a change in the code.In a RubyEdit which is fixed at the design stage, I can see the idea working well. But my aim was to have a generic droplist, whereby I could use Properties in a module to configure the visuals.
Maybe I’m missing something (as usual).
Cheers
Spogg
I’ve not tried to implement this but it leads me to a question:
If a brush or pen colour is changed external to the RubyEdit (as in my example) would this be picked up if it had been defined in the init method?
I understood the init method was only called at start-up, or when there was a change in the code.In a RubyEdit which is fixed at the design stage, I can see the idea working well. But my aim was to have a generic droplist, whereby I could use Properties in a module to configure the visuals.
Maybe I’m missing something (as usual).
Cheers
Spogg
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
Re: RUBY: Droplist selector uses massive CPU when copied
It doesn't matter if you get the colors from external or internal links.
What matters is, if you plan to change colors during runtime of the plugin. In short, if you give the user of your plugin access to the color settings. In that case it needs dynamic assignment. But fear not: Most pens and brushes can be defined once as explained, and their color changed later on, without creating a new class instance. Even the color of a color class can be changed without creating a new instance. Most of that infor however is the result of long sessions where I looked at the classes, Malc created and their instance methods. A lot of them were not described in the user guide. However, some of them are now described in the user guide, so that guide again is very informative read
A much better way for color management, btw., is to use my ACM. That tool allows you to setup and group as many colors as you wish (complete with color wheel, different models like RGB, HSV or Hexcolor, and easy copy or overwrite handling) all on the top layer of your schematic, while you just plug a little receiver wherever you need access to the colors. When publishing the plugin finally, you just remove the central managemant module. All the receivers keep their last selected color.
What matters is, if you plan to change colors during runtime of the plugin. In short, if you give the user of your plugin access to the color settings. In that case it needs dynamic assignment. But fear not: Most pens and brushes can be defined once as explained, and their color changed later on, without creating a new class instance. Even the color of a color class can be changed without creating a new instance. Most of that infor however is the result of long sessions where I looked at the classes, Malc created and their instance methods. A lot of them were not described in the user guide. However, some of them are now described in the user guide, so that guide again is very informative read
A much better way for color management, btw., is to use my ACM. That tool allows you to setup and group as many colors as you wish (complete with color wheel, different models like RGB, HSV or Hexcolor, and easy copy or overwrite handling) all on the top layer of your schematic, while you just plug a little receiver wherever you need access to the colors. When publishing the plugin finally, you just remove the central managemant module. All the receivers keep their last selected color.
Last edited by tulamide on Mon Jul 30, 2018 8:22 am, edited 1 time in total.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: RUBY: Droplist selector uses massive CPU when copied
Got it!
Thanks again tulamide
Cheers
Spogg
Thanks again tulamide
Cheers
Spogg
-
Spogg - Posts: 3358
- Joined: Thu Nov 20, 2014 4:24 pm
- Location: Birmingham, England
18 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 48 guests