It is currently September 29th, 2022, 5:56 pm

Reducing a cpu and memory usage of a skin

Tips and Tricks from the Rainmeter Community
nek
Posts: 65
Joined: November 3rd, 2019, 12:00 am

Reducing a cpu and memory usage of a skin

Post by nek »

This topic is for skin creators who knows how to write a basic skin code.


Skin: Displays an image file
toggle_on.png

Code: Select all

Skins
 └─ ToggleSwitch
      Skin.ini
      on.png

Code: Select all

[Rainmeter]
Update=1000

[Variables]
STATE=on

[Image]
Meter=Image
ImageName=#STATE#.png
DynamicVariables=1
πŸ“— Image Meter

This is a simple skin that displays an image file.
Have you ever written a code like this?
















I feel bad from that code and I never use DynamicVariables=1 option on that Image meter. Because my computer is old enough and I think the skin is wasting computer resources. πŸ“— Dynamic Variables

















The Rainmeter.exe opens on.png file and closes EVERY 1 SECOND. (loading from the disk/cache/memory?)
(The Operation column in the log, CreateFile means Open file in this case.)
process_monitor.png
Filter > Filter...
Process Name is Rainmeter.exe then Include > [Add] > [OK]
Microsoft Docs wrote:Process Monitor is an advanced monitoring tool for Windows that shows real-time file system, Registry and process/thread activity.

The following code got same result.

Code: Select all

[Rainmeter]
Update=1000

[MeasureState]
Measure=String
String=on

[Image]
Meter=Image
MeasureName=MeasureState
ImageName=%1.png
Rainmeter Docs wrote:If you are "binding" a measure to a meter with the MeasureName option, you don't need either [] or DynamicVariables. πŸ“— Dynamic Cheat Sheet, MeasureName

Conditions for image file to repeatedly be opened/closed

βœ”οΈ The skin has an Image meter that displays an image file. ImageName=something.png
βœ”οΈ The Image meter is in a skin frequent update cycle.
[Rainmeter] Update=1000 and [ImageMeter] UpdateDivider=-1 option is not set.
(or [Rainmeter] DefaultUpdateDivider=-1 is not set) πŸ“— UpdateDivider, DefaultUpdateDivider
🚫 DynamicVariables=1 or MeasureName=something option is set on the Image meter.


Reducing a cpu and memory usage of a Rainmeter skin

βœ”οΈ Control the Skin update rate with [Rainmeter] section Update option. Update=-1 Update=1000 Update=60000
βœ”οΈ Control the Measure and Meter update rate. Core Measure with UpdateDivider option.

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=-1
AccurateText=1
βœ”οΈ Use a DynamicVariables=1 only when necessary.
Especially avoid using DynamicVariables=1 MeasureName=something option on an Image Meter.
βœ”οΈ Set Disabled=1 option on a Script measure if the Lua script doesn't have a function Update().

Code: Select all

[MeasureScript]
Measure=Script
ScriptFile=something.lua
Disabled=1
βœ”οΈ Remove the unnecessary measures and meters.
βœ”οΈ Close the About Rainmeter window if you don't use.
βœ”οΈ Don't load a lot of high resolution images.
βœ”οΈ Use a Meter=String(Font file, *.ttf, *.otf) instead of a Meter=Image (Image file) as possible.

# General
tabler Icons - Download (2437 glyphs, 1189 KB)
Material Icons - Download (2226 glyphs, 347 KB)
RemixIcon - Download (2214 glyphs, 393 KB)
Boxicons - Download (1604 glyphs, 306 KB)
IcoFont - Download (2094 glyphs, 1017 KB)
Font Awesome Free Solid - Download (1389 glyphs, 388 KB)
Line Awesome Solid? - Download (931 glyphs, 220 KB)
ionicons - Download (699 glyphs, 109 KB)
Emoji icon font - Download (654 glyphs, 310 KB)
CoreUI Icons Free - Download (515 glyphs, 142 KB)
Elegant Icon - Download (364 glyphs, 58 KB)
Ligature Symbols - Download (360 glyphs, 82 KB)
Typicons - Download (337 glyphs, 98 KB)
Cryptocoins - Download (332 glyphs, 114 KB)
Elusive Icons - Download (307 glyphs, 78 KB)
Metrize Icons - Download (304 glyphs, 62 KB)
Foundation Icon Fonts - Download (286 glyphs, 56 KB)
Entypo - Download (285 glyphs, 74 KB)
Linearicons - Download (270 glyphs, 80 KB)
Open Iconic - Download (226 glyphs, 28 KB)
Font Awesome Free Regular - Download (211 glyphs, 61 KB)
MFG Labs Iconset - Download (211 glyphs, 55 KB)
Dripicons - Download (203 glyphs, 40 KB)
Line Awesome Regular - Download (146 glyphs, 33 KB)
Genericons Neue - Download (106 glyphs, 21 KB)
Modern Pictograms free ver. - Download (102 glyphs, 26 KB)
Nerd Fonts - Download (3705 glyphs, 826 KB)

# Weather
Weather Icons - Download (247 glyphs, 98 KB)
QWeather Icons - Download (225 glyphs, 72 KB)
Weather Icons Font Set - Download (208 glyphs, 80 KB)
IcoFont - Download (81 glyphs, 70 KB)
Climacons - Download (78 glyphs, 19 KB)
Meteocons - Download (50 glyphs, 25 KB)

# Map
Map Icons - Download (179 glyphs, 47 KB)

# Brands
CoreUI Icons Brand - Download (831 glyphs, 510 KB)
Font Awesome Brands Regular - Download (513 glyphs, 181 KB)
Line Awesome Brands - Download (418 glyphs, 152 KB)
Zocial icons - Download (106 glyphs, 49 KB)


πŸ” dp4 Font Viewer ... Glyph preview and Unicode value.
Settings
dp4_settings.png
dp4_family.png
Notes: Copy the font file to Skins\SomeSkin\@Resources\Fonts\SomeFont.ttf.
Hexadecimal Unicode value. Allowed range is x0 - xFFFE. πŸ“— Character Variables

Code: Select all

[ButtonZoomIn]
Meter=String
AntiAlias=1
FontFace=dripicons-v2
FontSize=16
Text=[\xE068]

πŸ“— Dynamic Cheat Sheet, [Rainmeter] Update, DefaultUpdateDivider [Measure] UpdateDivider, Script, Disabled [Meter] MeasureName

⭐ How a skin is updated, About an Update=1000 by jsmorley


πŸ’‘ Keep in mind You should not use the DynamicVariables=1 MeasureName=something option on an Image Meter that displays an image file, if the Image Meter is in a Skin frequent update cycle.
You do not have the required permissions to view the files attached to this post.
Last edited by nek on September 6th, 2022, 3:20 pm, edited 12 times in total.
nek
Posts: 65
Joined: November 3rd, 2019, 12:00 am

Re: Reducing a cpu and memory usage of a skin

Post by nek »

A couple of examples


Skin: Displays a rocket image and it changes image size with mouse scroll wheel.

rocket.png

Code: Select all

Skins
 └─ Rocket
      Skin.ini
      rocket.png
Before: The Rainmeter.exe opens/closes the image file every 1 second

Code: Select all

[Rainmeter]
Update=1000

[Variables]
SCALE=1.0

[Image]
Meter=Image
ImageName=rocket.png
W=(72*#SCALE#)
PreserveAspectRatio=1
SolidColor=F5F5F5
MouseScrollDownAction=[!SetVariable SCALE "(Clamp(#SCALE#-0.1, 0.5, 4.0))"][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseScrollUpAction=[!SetVariable SCALE "(Clamp(#SCALE#+0.1, 0.5, 4.0))"][!UpdateMeter #CURRENTSECTION#][!Redraw]
DynamicVariables=1
After
[Rainmeter] Changed Update=-1
[Image] Added MouseActions [!SetOption #CURRENTSECTION# DynamicVariables 0]
[Image] Removed DynamicVariables=1

Code: Select all

[Rainmeter]
Update=-1
;DefaultUpdateDivider=-1

[Variables]
SCALE=1.0

[Image]
Meter=Image
ImageName=rocket.png
W=(72*#SCALE#)
PreserveAspectRatio=1
SolidColor=F5F5F5
MouseScrollDownAction=[!SetVariable SCALE "(Clamp(#SCALE#-0.1, 0.5, 4.0))"][!SetOption #CURRENTSECTION# DynamicVariables 0][!UpdateMeter #CURRENTSECTION#][!Redraw]
MouseScrollUpAction=[!SetVariable SCALE "(Clamp(#SCALE#+0.1, 0.5, 4.0))"][!SetOption #CURRENTSECTION# DynamicVariables 0][!UpdateMeter #CURRENTSECTION#][!Redraw]
πŸ“— PreserveAspectRatio, Mouse Actions, !SetVariable, Clamp, #CURRENTSECTION#, !SetOption Guide

⭐ Controlling Dynamic Variables by smurfier (LuaCalendar)
[!SetOption SECTION_NAME DynamicVariabls 0][!UpdateMeasure(or !UpdateMeter) SECTION_NAME] technique is very useful for one time resolving dynamic variables. Thank you, smurfier!




Skin: Displays 1-12 o'clock images and it changes every hour.

12.png

Code: Select all

Skins
 └─ OClock
      Skin.ini
      1.png
      2.png
      3.png
      4.png
      5.png
      6.png
      7.png
      8.png
      9.png
      10.png
      11.png
      12.png
Before: The Rainmeter.exe opens/closes the image file every 1 second

Code: Select all

[Rainmeter]
Update=1000

[MeasureHour]
Measure=Time
Format=%#I
;; Update every 1 second

[Image]
Meter=Image
ImageName=[MeasureHour].png
DynamicVariables=1
;; Update every 1 second
After
[Rainmeter] Added DefaultUpdateDivider=-1
[MeasureHour]Added OnChangeAction=[!SetOption ...
[MeasureHour] Added UpdateDivider=1
[Image] Removed DynamicVariables=1

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=-1

[MeasureHour]
Measure=Time
Format=%#I
OnChangeAction=[!SetOption Image ImageName "[#CURRENTSECTION#].png"][!UpdateMeter Image][!Redraw]
UpdateDivider=1
;; Update every 1 second

[Image]
Meter=Image
ImageName=[MeasureHour].png
;; Update every 3600 seconds (1 hour)
%#I Hour in 12-hour format (1 - 12) πŸ“— Format codes - Time measure

You might think there is a section variable ImageName=[MeasureHour].png option on the Image meter, DynamicVariables=1 option is needed.
Rainmeter Docs wrote:Section variables are always dynamic. DynamicVariables=1 will always be needed on a measure or meter section where the variable is used in an option value. πŸ“— Dynamic Variables - Section Variables
That ImageName=[MeasureHour].png is used only once and Variables are resolved dynamically during the first skin loading.
πŸ“— OnChangeAction




Skin: Displays Weather condition images and it updates every 10 minutes.

sunny.png

Code: Select all

Skins
 └─ Weather
      Skin.ini
      1.png ... sunny
      2.png ... cloudy
      3.png ... rain
Before: The Rainmeter.exe opens/closes the image file every 1 second

Code: Select all

[Rainmeter]
Update=1000

[MeasureWebParser]
Measure=WebParser
URL=https://www.example.com/something
RegExp=^[\s\S]*$
FinishAction=(some actions)

[@CurrentIcon]
Measure=WebParser
URL=[MeasureWebParser]
RegExp=(some regular expressions)

[Icon]
Meter=Image
W=72
MeasureName=@CurrentIcon
PreserveAspectRatio=1
SolidColor=F5F5F5
DynamicVariables=1
After
[Rainmeter] Changed Update=60000
[Rainmeter] Added DefaultUpdateDivider=-1
[MeasureWebParser] FinishAction Added [!UpdateMeasure @CurrentIcon]
[MeasureWebParser] Added UpdateRate=10
[MeasureWebParser] Added UpdateDivider=1
[@CurrentIcon] Added OnChangeAction=[!SetOption ...
[Icon] Added ImageName=1.png
[Icon] Removed MeasureName=@CurrentIcon
[Icon] Removed DynamicVariables=1

Code: Select all

[Rainmeter]
Update=60000
DefaultUpdateDivider=-1

[MeasureWebParser]
Measure=WebParser
URL=https://www.example.com/something
RegExp=^[\s\S]*$
FinishAction=(some actions)[!UpdateMeasure @CurrentIcon]
UpdateRate=10
UpdateDivider=1

[@CurrentIcon]
Measure=WebParser
URL=[MeasureWebParser]
RegExp=(some regular expressions)
OnChangeAction=[!SetOption Icon ImageName [#CURRENTSECTION#]][!UpdateMeter Icon][!Redraw]

[Icon]
Meter=Image
ImageName=1.png
W=72
PreserveAspectRatio=1
SolidColor=F5F5F5
πŸ“— WebParser measure, WebParser: How UpdateRate Works
⭐ Some explanation of timing and WebParser by jsmorley
You do not have the required permissions to view the files attached to this post.
Last edited by nek on September 4th, 2022, 1:59 pm, edited 3 times in total.
nek
Posts: 65
Joined: November 3rd, 2019, 12:00 am

Re: Reducing a cpu and memory usage of a skin

Post by nek »

πŸ’‘ Keep in mind You should not use the DynamicVariables=1 MeasureName=something option on an Image Meter that displays an image file, if the Image Meter is in a Skin frequent update cycle.




What is DefaultUpdateDivider=-1 for?

A Rainmeter skin is defined the Update=1000 DefaultUpdateDivider=1 option by default.
This means that all measures and meters are updating once every 1 second. ⭐ How a skin is updated

Code: Select all

[Rainmeter]
Update=1000

[MeasureCalc]
Measure=Calc

[MeasureString]
Measure=String

[MeterText]
Meter=String
Text=Something
is equal to

Code: Select all

[Rainmeter]
Update=1000

[MeasureCalc]
Measure=Calc
UpdateDivider=1

[MeasureString]
Measure=String
UpdateDivider=1

[MeterText]
Meter=String
Text=Something
UpdateDivider=1

DefaultUpdateDivider=-1
Rainmeter Docs wrote:If DefaultUpdateDivider=-1 or any negative number, then by default all measures and meters are only updated once when the skin is loaded or refreshed.

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=-1

[MeasureCalc]
Measure=Calc

[MeasureString]
Measure=String

[MeterText]
Meter=String
Text=Something
is equal to

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=-1

[MeasureCalc]
Measure=Calc
UpdateDivider=-1

[MeasureString]
Measure=String
UpdateDivider=-1

[MeterText]
Meter=String
Text=Something
UpdateDivider=-1



For example: There is a digital clock skin.
digital_clock.png
Before: Standard code

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

[MeasureTime]
Measure=Time
Format=%H:%M
;; Update every 1 second

[MeterTime]
Meter=String
MeasureName=MeasureTime
Text=%1
AntiAlias=1
FontSize=36
;; Update every 1 second
After: Advanced code
[Rainmeter] Added DefaultUpdateDivider=-1
[MeasureTime] Added OnChangeAction=[!UpdateMeter MeterTime]
[MeasureTime] Added UpdateDivider=1

Code: Select all

[Rainmeter]
Update=1000
DefaultUpdateDivider=-1
AccurateText=1

[MeasureTime]
Measure=Time
Format=%H:%M
OnChangeAction=[!UpdateMeter MeterTime]
UpdateDivider=1
;; Update every 1 second

[MeterTime]
Meter=String
MeasureName=MeasureTime
Text=%1
AntiAlias=1
FontSize=36
;; Update every 60 seconds
ONLY 1 measure: [MeasureTime] (Core Measure) requires to be defined the UpdateDivider=1



core_measure.png
You do not have the required permissions to view the files attached to this post.