It is currently March 29th, 2024, 6:51 am

Question on DynamicVariables=1

Get help with creating, editing & fixing problems with skins
User avatar
mmxiv
Posts: 18
Joined: February 14th, 2021, 5:48 pm

Re: Question on DynamicVariables=1

Post by mmxiv »

Thanks but I don't understand why does the Hidden option have not UpdateDivider=-1 by default, when its value is 1? It would be more efficient way to work with it and save the performance.
Why to update sth unused on every update cycle by default?
Even if there is a need for it, it should be done from an external action, not always on by default.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Question on DynamicVariables=1

Post by Yincognito »

mmxiv wrote: February 21st, 2021, 11:44 pm Thanks but I don't understand why does the Hidden option have not UpdateDivider=-1 by default, when its value is 1? It would be more efficient way to work with it and save the performance.
Why to update sth unused on every update cycle by default?
Even if there is a need for it, it should be done from an external action, not always on by default.
The developers would probably answer this better, but in my view, there might be some reasons:
- both the Hidden and UpdateDivider options are separate options, independent of each other, as they mean different things
- having both the options independent allows for greater flexibility (e.g. "enable" one, but "disable" the other and viceversa)
- being independent of each other makes a moving meter "travel" the "normal" distance along its path even if hidden (this may be useful in some cases), or a text meter update its changing text (e.g. say, a Quote plugin meter) on showing, after temporarily being hidden
- as pointed out already, it's the redraw process (and not the actual update process) that is the most CPU intensive in the case of meters, and since hiding the meter basically makes it have a width and height of 0 (thus no significant resources being used for redrawing), additonally setting the UpdateDivider to -1 becomes more or less pointless as resources have been already mostly saved by the former, at least in the case of static, regular meters updated in a classic 1 second fashion
- setting the UpdateDivider to -1 based on a variable storing the Hidden state is not that difficult to do, as you already wrote; of course, it becomes more laborious to do if there are many meters, but including them in a group and then operating on that group using bangs makes it easier

In my experience, setting the UpdateDivider to -1 to conserve resources is mostly needed for big, complex and fast updated animated skins, like for example, my Solar System skin (working on that skin is what made me realize that in some cases, setting the UpdateDivider to -1 is a must, which is why I used it when pausing the animation on left click).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Question on DynamicVariables=1

Post by balala »

mmxiv wrote: February 21st, 2021, 11:44 pm I don't understand why does the Hidden option have not UpdateDivider=-1 by default, when its value is 1?
There is an error in this judgement / question. There is no such thing as UpdateDivider of an option. The UpdateDivider is related to the section (meter or measure), not to a single option (Hidden) of a meter.
User avatar
mmxiv
Posts: 18
Joined: February 14th, 2021, 5:48 pm

Re: Question on DynamicVariables=1

Post by mmxiv »

balala wrote: February 22nd, 2021, 10:10 am There is an error in this judgement / question. There is no such thing as UpdateDivider of an option. The UpdateDivider is related to the section (meter or measure), not to a single option (Hidden) of a meter.
@ Yincognito too

No, there is not. You just have misunderstood meh.
I think that the Rainmeter devs should rewrite the functionality of the Hidden option in C++ so that when it is set to Hidden=1, it does not update the meter on every update cycle of the skin but behaves like the meter has UpdateDivider=-. For the time being, Hidden=1 still updates the meter either you use it or not if you don't add an UpdateDivider=-1 to it. There could be a need for updating a hidden meter, but shouldn't it be only updated when we use the skin, for instance on a mouse action over, mouse click, depending on Variable values etc.? In my opinion it would be more effective for for making a quick gadget and I am affraid that even some popular Rainmeter skin creators ain't aware of that just hidden meters still use some significant amount of the system resources that increases with the number of the meters. Imagine if one have a Processor skin that works with up to 64 physical core like 3990X has, and then someone use the skin for a six, or eight core CPU, all the hidden meter from 8 on will be hidden but will affect CPU performance not just a little bit. Even if every of the core meters and measures have groups, you have to set UpdateDivides=-1 for all 64 of them in the skin, at least but why?
I am one, but some other skin creators should put the thing into practive and evaluate what is really the better solution, the one I am talking about or to keep it as is.
As far as I am concerned, it should be changed. Try to convince me that the current situation with that is the better.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question on DynamicVariables=1

Post by jsmorley »

The amount of resources used to "update" a meter is so small it really rounds to zero. The real "work" that is done is primarily in two places. First, in the measure that is bound to the meter that actually measures the resources and returns a value, and second, in the redraw portion of the skin update cycle, where the meter is actually constructed and drawn. What is done in the update of a meter is pretty much that the meter asks Rainmeter for the current value of any measure(s) bound to it. This is pretty much copying a number or string value from one bit of memory to another, and is just a tiny amount of work. This varies a bit depending on the meter type, and meters like Histogram do a little more work in the update cycle, but honestly, worrying about updates of meters, even a ton of them, is not where you are going to get any significant savings. The real work, the work that can really impact resources, is done in the redraw cycle of the overall skin.

Using Hidden=1 on a meter both visibly hides the meter, and reduces the amount of work Rainmeter does during the redraw cycle significantly. There is nothing wrong with setting the meter to not update at the same time, and I'm never opposed to going as far as you like to fine-tune things. However, I see no reason to take away any flexibility in this matter, since as has been pointed out, there could be "movement" or changes to other meter options that you might want to take place on each update, even if you don't see the result right away. I'm perfectly fine if you want to tie the state of "hidden" with the state of "update" as you like, but I'd be opposed to forcing that.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Question on DynamicVariables=1

Post by Yincognito »

Yep, in a way, the question "Why isn't the UpdateDivider automatically set to -1 when Hidden=1?" is similar to "Why isn't the Redraw process happening automatically when Updating a section?" - because from a user's visual and logical point of view, the former operations should usually follow the latter ones in most scenarios. The thing is. Rainmeter has a nice modular way in which it is built, and most of the times, an operation that seems singular to an user is in fact "broken" into more technically separated/independent operations, and that allows a skin designer to manipulate things in a way that wouldn't be possible if some operations would automatically follow others. For example, updating multiple meters before doing a single redraw, or hide multiple meters before setting UpdateDivider to -1 on them a single time.

That being said, I'm not sure what your code looks like (in my view, such a code needs other optimizations as well, if the update divider thing is a problem - just saying), but you can do things easier, by just pasting:

Code: Select all

UpdateDivider=(([#CURRENTSECTION#:W]*[#CURRENTSECTION#:H]=0)?(-1):(1))
DynamicVariables=1
in the meters that you want to not be updated after being hidden, like demonstrated in the code below:

Code: Select all

[Variables]
Updates=0

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Meters---

[Image]
Meter=Image
W=100
H=100
SolidColor=247,47,47,255
UpdateDivider=(([#CURRENTSECTION#:W]*[#CURRENTSECTION#:H]=0)?(-1):(1))
OnUpdateAction=[!SetVariable Updates (#Updates#+1)]
DynamicVariables=1

[Text]
Meter=STRING
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=15
AntiAlias=1
Text="W=[Image:W], H=[Image:H], U=#Updates#"
LeftMouseUpAction=[!ToggleMeter Image][!UpdateMeter *][!Redraw]
DynamicVariables=1
Left clicking on the text toggles the hidden state of the image, and because of the conditional in the latter's UpdateDivider option (which can be applied to any meter whatsoever, because of the #CURRENTSECTION# and dynamic variables being used), the image stops being updated. This is clearly proven by the U=... part (counting the image updates), whose value stays the same after hiding the meter.

This is based on the fact that once hidden, a meter has its W and H set to 0, and this is what the conditional tests. Sure, if you want to be really precise, you'd test whether both W and H are 0 (currently, the possibility of either W or H is 0 is tested), but that's simple to adjust in the formula - let me know if you want to. I mean, after all, a meter is "invisible" even if just one of its W and H is 0, right? :confused:

P.S. Obviously, you'd still need to !Update stuff after toggling the hidden state, but that's easily achieved by either mass updating (the * part) or, if feasible, by a general update.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Question on DynamicVariables=1

Post by balala »

mmxiv wrote: February 22nd, 2021, 3:38 pm No, there is not. You just have misunderstood meh.
Sorry, my bad.
User avatar
mmxiv
Posts: 18
Joined: February 14th, 2021, 5:48 pm

Re: Question on DynamicVariables=1

Post by mmxiv »

Yincognito wrote: February 22nd, 2021, 5:28 pm Yep, in a way, the question "Why isn't the UpdateDivider automatically set to -1 when Hidden=1?" is similar to "Why isn't the Redraw process happening automatically when Updating a section?" - because from a user's visual and logical point of view, the former operations should usually follow the latter ones in most scenarios. The thing is. Rainmeter has a nice modular way in which it is built, and most of the times, an operation that seems singular to an user is in fact "broken" into more technically separated/independent operations, and that allows a skin designer to manipulate things in a way that wouldn't be possible if some operations would automatically follow others. For example, updating multiple meters before doing a single redraw, or hide multiple meters before setting UpdateDivider to -1 on them a single time.

That being said, I'm not sure what your code looks like (in my view, such a code needs other optimizations as well, if the update divider thing is a problem - just saying), but you can do things easier, by just pasting:

Code: Select all

UpdateDivider=(([#CURRENTSECTION#:W]*[#CURRENTSECTION#:H]=0)?(-1):(1))
DynamicVariables=1
in the meters that you want to not be updated after being hidden, like demonstrated in the code below:

Code: Select all

[Variables]
Updates=0

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Meters---

[Image]
Meter=Image
W=100
H=100
SolidColor=247,47,47,255
UpdateDivider=(([#CURRENTSECTION#:W]*[#CURRENTSECTION#:H]=0)?(-1):(1))
OnUpdateAction=[!SetVariable Updates (#Updates#+1)]
DynamicVariables=1

[Text]
Meter=STRING
Y=0R
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=15
AntiAlias=1
Text="W=[Image:W], H=[Image:H], U=#Updates#"
LeftMouseUpAction=[!ToggleMeter Image][!UpdateMeter *][!Redraw]
DynamicVariables=1
Left clicking on the text toggles the hidden state of the image, and because of the conditional in the latter's UpdateDivider option (which can be applied to any meter whatsoever, because of the #CURRENTSECTION# and dynamic variables being used), the image stops being updated. This is clearly proven by the U=... part (counting the image updates), whose value stays the same after hiding the meter.

This is based on the fact that once hidden, a meter has its W and H set to 0, and this is what the conditional tests. Sure, if you want to be really precise, you'd test whether both W and H are 0 (currently, the possibility of either W or H is 0 is tested), but that's simple to adjust in the formula - let me know if you want to. I mean, after all, a meter is "invisible" even if just one of its W and H is 0, right? :confused:

P.S. Obviously, you'd still need to !Update stuff after toggling the hidden state, but that's easily achieved by either mass updating (the * part) or, if feasible, by a general update.
It is fine when Redraw is off by default and does not come along with Update and we simpy add it just where necessary, while updating a hidden meter is ON by default EVERYWHERE and one must put some effort just to stop it.
Should someone keep his car running all the time because he will drive it, time after time? :)

Good example and now, could you make the same gadget/example with imagination that the hidden meters does not update by default and compare what is simpler and more efficient?

Edit: in fact, this exact example wouldn't prove a lot in that case, wouldn't be a lot of difference. It would be almost the same. Need something more complex for this experiment.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Question on DynamicVariables=1

Post by Yincognito »

mmxiv wrote: February 22nd, 2021, 7:17 pm It is fine when Redraw is off by default and does not come along with Update and we simpy add it just where necessary, while updating a hidden meter is ON by default EVERYWHERE and one must put some effort just to stop it.

Good example and now, could you make the same gadget/example with imagination that the hidden meters does not update by default and compare what is simpler and more efficient?
Good point (and example), LOL. But I can easily reverse it and make it look the opposite:
- we can simply add the setting of the UpdateDivider to -1 where necessary as well, just like adding the Redraw
- the same effort goes into adding a [!Redraw] EVERYTIME after an [!Update...] as adding the part that prevents updating a hidden meter
It depends on where you look at this from, really. If you have meters that need to stop updating after being hidden, you'll find it simpler to have it done automatically; if you have meters that need to keep updating after being hidden, you'll find it simpler the way it is now. Someone that needs his meters to keep updating after being hidden would be equally upset that he has to prevent the automatic stopping of the update, if the way you propose to happen would be implemented instead.

But then, the real problem is technical. The way it is now, the update divider can easily be set to -1 when needed, by adding simple bits to the code, similar to adding the redrawing, as mentioned above (unless you think copy pasting is hard, that is). But ok, I'll play along, let's imagine that an automatic stop of updating would be done on hiding a meter as you envisioned though ... can you explain how much easy it would be to "restore" the updating of a meter on showing it back? You'd probably say it's as simple as setting back its update divider to 1. WRONG! What if you have 100 meters, each working on a different "original" update divider? In such a case, you'd have to add 100 bangs setting back the specific update dividers to what they originally were, another 100 bangs updating the meters to get their new settings (sure, this can be reduced to just 1, if groups are used, but still), and probably a redraw bang as well, to make the changes reflect visually - so a minimum of 102 bangs for 100 meters. At least "manually" stoping updating deals only with setting a general -1 value and it works on every meter, unlike restoring many different update dividers. So... which variant is "simpler and more efficient" again? :D
mmxiv wrote: February 22nd, 2021, 7:17 pmShould someone keep his car running all the time because he will drive it, time after time? :)
Well, I've seen drivers keeping their car engines running when getting out and do some 2 minute quick job. Someone would also not turn off the light in their living room when they go to the toilet and do their "number one" thing. They would also keep the water flowing while their soap up their hands, keep the computer on even if they watch the TV for a minute, keep their social media on even if they're not actively using it in that moment, etc. Sure, it's a waste of resources, bad for the environment and so on, but in most cases it's simpler. Probably not more efficient, but in our case, it's not a matter of not being able to be efficient, it's just a matter of how convenient is to do it one way vs the other - please correct me if I'm wrong here.
mmxiv wrote: February 22nd, 2021, 7:17 pmEdit: in fact, this exact example wouldn't prove a lot in that case, wouldn't be a lot of difference. It would be almost the same. Need something more complex for this experiment.
Exactly. That's why I said that the code probably needs optimization in other areas as well, if the update of hidden meters has such an impact on the CPU usage. It's true that sometimes all the optimization won't help as much, but that is only in the case of already CPU heavy skins, like I mentioned earlier.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mmxiv
Posts: 18
Joined: February 14th, 2021, 5:48 pm

Re: Question on DynamicVariables=1

Post by mmxiv »

Hello! I have 2 questions if someone could give the right answer:

#1: In case 1 of the measure1, will the measure2 and meter1 be updated in every case, true and false?

Code: Select all

[Rainmeter]
Update=1000

[measure1]
Measure=NetOut
IfCondition=(#CURRENTSECTION# > 0)
IfTrueAction=[!EnableMeasure "measure2"]
IfFalseAction=[!DisableMeasure "measure2"]
OnChangeAction=[!UpdateMeasure "measure2"][!UpdateMeter "meter1"]
DynamicVariables=1

[measure2]
Measure=Calc
Formula=measure1
...
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[meter1]
...
UpdateDivider=-1

#2: In case 2, will the measure2 and meter1 be updated every 1 sec and will the same happen in every of the scenarios, true and false?

Code: Select all

[Rainmeter]
Update=1000

[measure1]
Measure=NetOut
IfCondition=(#CURRENTSECTION# > 0)
IfTrueAction=[!EnableMeasure "measure2"][!UpdateMeasure "measure2"][!UpdateMeter "meter1"]
IfFalseAction=[!DisableMeasure "measure2"][!UpdateMeasure "measure2"][!UpdateMeter "meter1"]
DynamicVariables=1

[measure2]
Measure=Calc
Formula=measure1
...
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[meter1]
...
UpdateDivider=-1