1
0
mirror of https://github.com/gryf/tabbedalt.git synced 2026-04-26 08:21:26 +02:00

Added more memory optimizations

This commit is contained in:
2026-04-21 18:44:43 +02:00
parent b811ca58f6
commit 57f5423dc4
2 changed files with 50 additions and 3 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:
+49 -2
View File
@@ -166,6 +166,12 @@
# 2026-04-21 16:29:49
# - Fix small but constant memory consumption, which over time eventually will
# cause urxvt to consume huge amount of memory
#
# 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
# properties variables after use, update only changed X properties
use Scalar::Util;
@@ -755,6 +761,18 @@ sub tab_start {
sub tab_destroy {
my ($self, $tab) = @_;
# Disable hooks and remove data from tab
$tab->disable('line_update', 'key_press', 'property_notify', 'action', 'start', 'destroy');
delete $tab->{lastActivity};
delete $tab->{is_being_renamed};
delete $tab->{old_name};
delete $tab->{new_name};
delete $tab->{overlay};
delete $tab->{main};
delete $tab->{parent};
delete $tab->{'tabbedalt_main'};
delete $tab->{name};
$self->{tabs} = [ grep $_ != $tab, @{ $self->{tabs} } ];
if (@{ $self->{tabs} }) {
@@ -786,8 +804,37 @@ sub command {
sub tab_property_notify {
my ($self, $tab, $event) = @_;
$self->copy_properties
if $event->{window} == $tab->parent;
return () unless $event->{window} == $tab->parent;
return () unless $tab == $self->{cur};
# 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");
# fix up size hints
if ($atom == $wm_normal_hints) {
my (@hints) = unpack "l!*", $items;
$hints[$_] += $self->{tabheight} for (4, 6, 16);
$items = pack "l!*", @hints;
}
$self->XChangeProperty ($self->parent, $atom, $type, $format, $items);
$self->{current_properties}{$atom} = [$type, $format, $items];
# free memory from X properties
undef $type;
undef $format;
undef $items;
()
}