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
+1 -1
View File
@@ -266,7 +266,7 @@ additional resources that can be set. First one, disabled by default is::
URxvt.tabbedalt.confirm-quit: false
When set to ``true`` it will either execute a message program or will display
When set to ``true`` it will either execute a message program or will display
an urxvt overlay with the dialog directly on current tab. Note that overlay
dialog will expect the user to either press:
+19 -34
View File
@@ -170,25 +170,8 @@
# 2026-04-21 18:34:16
# - Make some more optimization on memory usage - remove data from destroyed
# 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
#
# 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;
@@ -302,7 +285,10 @@ sub refresh {
$self->{tabheight} = $self->{_tabheight};
}
$self->configure;
if ($old_tabheight != $self->{tabheight}) {
$self->configure;
$self->copy_properties;
}
my $ncol = $self->ncol;
@@ -428,8 +414,8 @@ sub copy_properties {
my $current = delete $self->{current_properties};
# pass 1: copy over properties different or nonexisting
for my $atom ($tab->XListProperties($tab->parent)) {
my ($type, $format, $items) = $self->XGetWindowProperty($tab->parent, $atom);
for my $atom ($tab->XListProperties ($tab->parent)) {
my ($type, $format, $items) = $self->XGetWindowProperty ($tab->parent, $atom);
# fix up size hints
if ($atom == $wm_normal_hints) {
@@ -441,29 +427,22 @@ sub copy_properties {
$hints[$_] += $self->{tabheight} for (4, 6, 16);
$items = pack "l!*", @hints;
undef @hints;
}
my $cur = delete $current->{$atom};
# update if changed, we assume empty items and zero type and format will not happen
$self->XChangeProperty($self->parent, $atom, $type, $format, $items)
$self->XChangeProperty ($self->parent, $atom, $type, $format, $items)
if $cur->[0] != $type or $cur->[1] != $format or $cur->[2] ne $items;
$self->{current_properties}{$atom} = [$type, $format, $items];
undef $type;
undef $format;
undef $items;
undef $atom;
undef $cur;
}
# pass 2, delete all extraneous properties
$self->XDeleteProperty ($self->parent, $_) for keys %$current;
undef $current;
undef $wm_normal_hints;
}
sub make_current {
@@ -487,6 +466,7 @@ sub make_current {
$self->{cur} = $tab;
$tab->enable_activity_hook(0);
$self->configure;
$self->copy_properties;
$tab->focus_out; # just in case, should be a nop
@@ -685,6 +665,7 @@ _on start => sub {
_on configure_notify => sub {
my ($self, $event) = @_;
$self->configure;
$self->refresh;
()
@@ -826,11 +807,16 @@ sub tab_property_notify {
return () unless $event->{window} == $tab->parent;
return () unless $tab == $self->{cur};
# update only the changed selected property instead of all properties
my $atom = $event->{atom};
my %allowed = map { $_ => 1 } qw(WM_NORMAL_HINTS _NET_WM_NAME WM_NAME);
return () unless ($allowed{$self->XGetAtomName($atom)});
# skip if called too often (within 0.1s)
my $now = urxvt::NOW;
my $last = $self->{last_property_update} // 0;
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 $wm_normal_hints = $self->XInternAtom ("WM_NORMAL_HINTS");
@@ -846,7 +832,6 @@ sub tab_property_notify {
$self->{current_properties}{$atom} = [$type, $format, $items];
# free memory from X properties
undef $wm_normal_hints;
undef $type;
undef $format;
undef $items;