greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.82k stars 472 forks source link

Defer icon lookup until formatting #1926

Closed bim9262 closed 11 months ago

bim9262 commented 11 months ago

See #1774

Let me know if you think this is a good approach to only set the required values needed based on the format that's being used.

MaxVerevkin commented 11 months ago

I think this kind of optimization has potential. In particular if we could actually skip expensive computation of values that are not used. For example, in net block, we may entirely skip IP address fetch if it is not present in the format.

However I am not sure if doing so for backlight or apt makes much sense. brightness and count are most certainly present - why would anyone use this block but not use it's only feature?

As for icons, instead of resolving them immediately (as in Value::icon(api.get_icon("gpu")?)), we can do so inside a formatter (so this becomes Value::icon("gpu")). This way unused icons are never actually fetched, which takes care of #1774.

bim9262 commented 11 months ago

As for icons, instead of resolving them immediately (as in Value::icon(api.get_icon("gpu")?)), we can do so inside a formatter (so this becomes Value::icon("gpu")). This way unused icons are never actually fetched, which takes care of https://github.com/greshake/i3status-rust/issues/1774.

I like that! I'll give that a go. We'll need to handle the icon progressions in the formatter too...

MaxVerevkin commented 11 months ago

Looks great!