Compare commits

..
1 Commits
Author SHA1 Message Date
gryf f57e535e64 Added more memory optimizations 2026-04-21 18:44:43 +02:00
2 changed files with 20 additions and 35 deletions
+14 -29
View File
@@ -172,23 +172,6 @@
# tab and disable its hooks # tab and disable its hooks
# - update tab property notifications, don't update it too often, clean up X # - update tab property notifications, don't update it too often, clean up X
# properties variables after use, update only changed X properties # properties variables after use, update only changed X properties
#
# 2026-08-10 17:20:53
# - remove variables in copy_properties to free memory
# - call configure() every time on refresh
# - removed throttling to suppress tab property notifications, as they need to
# be applied as every call there is different atom to process.
#
# 2026-08-11 18:42:45
# - removed call copy_properties() call from refresh() to avoid unnecessary
# Xlib interaction (to spare memory as the consequence) and rely only on
# notifications.
# - removed call for configure() from places, which will call refresh() as in
# refresh() configure will be called anyway.
#
# 2026-08-12 20:40:54
# - narrow down X properties which will be updated during tab_property_notify,
# which should slightly improve memory consumption.
use Scalar::Util; use Scalar::Util;
@@ -302,7 +285,10 @@ sub refresh {
$self->{tabheight} = $self->{_tabheight}; $self->{tabheight} = $self->{_tabheight};
} }
if ($old_tabheight != $self->{tabheight}) {
$self->configure; $self->configure;
$self->copy_properties;
}
my $ncol = $self->ncol; my $ncol = $self->ncol;
@@ -441,7 +427,6 @@ sub copy_properties {
$hints[$_] += $self->{tabheight} for (4, 6, 16); $hints[$_] += $self->{tabheight} for (4, 6, 16);
$items = pack "l!*", @hints; $items = pack "l!*", @hints;
undef @hints;
} }
my $cur = delete $current->{$atom}; my $cur = delete $current->{$atom};
@@ -451,19 +436,13 @@ sub copy_properties {
if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items; if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
$self->{current_properties}{$atom} = [$type, $format, $items]; $self->{current_properties}{$atom} = [$type, $format, $items];
undef $type; undef $type;
undef $format; undef $format;
undef $items; undef $items;
undef $atom;
undef $cur;
} }
# pass 2, delete all extraneous properties # pass 2, delete all extraneous properties
$self->XDeleteProperty ($self->parent, $_) for keys %$current; $self->XDeleteProperty ($self->parent, $_) for keys %$current;
undef $current;
undef $wm_normal_hints;
} }
sub make_current { sub make_current {
@@ -487,6 +466,7 @@ sub make_current {
$self->{cur} = $tab; $self->{cur} = $tab;
$tab->enable_activity_hook(0); $tab->enable_activity_hook(0);
$self->configure;
$self->copy_properties; $self->copy_properties;
$tab->focus_out; # just in case, should be a nop $tab->focus_out; # just in case, should be a nop
@@ -685,6 +665,7 @@ _on start => sub {
_on configure_notify => sub { _on configure_notify => sub {
my ($self, $event) = @_; my ($self, $event) = @_;
$self->configure;
$self->refresh; $self->refresh;
() ()
@@ -826,11 +807,16 @@ sub tab_property_notify {
return () unless $event->{window} == $tab->parent; return () unless $event->{window} == $tab->parent;
return () unless $tab == $self->{cur}; return () unless $tab == $self->{cur};
# update only the changed selected property instead of all properties # skip if called too often (within 0.1s)
my $atom = $event->{atom}; my $now = urxvt::NOW;
my %allowed = map { $_ => 1 } qw(WM_NORMAL_HINTS _NET_WM_NAME WM_NAME); my $last = $self->{last_property_update} // 0;
return () unless ($allowed{$self->XGetAtomName($atom)}); if ($now - $last < 0.1) {
return ();
}
$self->{last_property_update} = $now;
# update only the changed property instead of all properties
my $atom = $event->{atom};
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom); my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS"); my $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
@@ -846,7 +832,6 @@ sub tab_property_notify {
$self->{current_properties}{$atom} = [$type, $format, $items]; $self->{current_properties}{$atom} = [$type, $format, $items];
# free memory from X properties # free memory from X properties
undef $wm_normal_hints;
undef $type; undef $type;
undef $format; undef $format;
undef $items; undef $items;