From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2D7311FBF4 for ; Wed, 10 Jun 2020 07:07:31 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 63/82] imap: split ->logged_in attribute into a separate class Date: Wed, 10 Jun 2020 07:05:00 +0000 Message-Id: <20200610070519.18252-64-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is one boolean attribute not worth wasting space for. With 20000 sockets, this reduces RSS by around 5% at a glance, and locked hashes doesn't do us much good when clients use compression, anyways. --- lib/PublicInbox/IMAP.pm | 19 ++++++++++++++----- lib/PublicInbox/IMAPdeflate.pm | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 13f415cf8d6..803ce31ff22 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -16,7 +16,7 @@ package PublicInbox::IMAP; use strict; use base qw(PublicInbox::DS); -use fields qw(imapd logged_in ibx long_cb -login_tag +use fields qw(imapd ibx long_cb -login_tag uid_min -idle_tag -idle_max); use PublicInbox::Eml; use PublicInbox::EmlContentFoo qw(parse_content_disposition); @@ -27,6 +27,7 @@ use Text::ParseWords qw(parse_line); use Errno qw(EAGAIN); use Time::Local qw(timegm); use POSIX qw(strftime); +use Hash::Util qw(unlock_hash); # dependency of fields for perl 5.10+, anyways my $Address; for my $mod (qw(Email::Address::XS Mail::Address)) { @@ -91,7 +92,8 @@ sub greet ($) { sub new ($$$) { my ($class, $sock, $imapd) = @_; - my $self = fields::new($class); + my $self = fields::new('PublicInbox::IMAP_preauth'); + unlock_hash(%$self); my $ev = EPOLLIN; my $wbuf; if ($sock->can('accept_SSL') && !$sock->accept_SSL) { @@ -110,13 +112,15 @@ sub new ($$$) { $self; } +sub logged_in { 1 } + sub capa ($) { my ($self) = @_; # dovecot advertises IDLE pre-login; perhaps because some clients # depend on it, so we'll do the same my $capa = 'CAPABILITY IMAP4rev1 IDLE'; - if ($self->{logged_in}) { + if ($self->logged_in) { $capa .= ' COMPRESS=DEFLATE'; } else { if (!($self->{sock} // $self)->can('accept_SSL') && @@ -129,7 +133,7 @@ sub capa ($) { sub login_success ($$) { my ($self, $tag) = @_; - $self->{logged_in} = 1; + bless $self, 'PublicInbox::IMAP'; my $capa = capa($self); "$tag OK [$capa] Logged in\r\n"; } @@ -154,7 +158,7 @@ sub cmd_close ($$) { sub cmd_logout ($$) { my ($self, $tag) = @_; - delete @$self{qw(logged_in -idle_tag)}; + delete $self->{-idle_tag}; $self->write(\"* BYE logging out\r\n$tag OK Logout done\r\n"); $self->shutdn; # PublicInbox::DS::shutdn undef; @@ -1238,4 +1242,9 @@ no warnings 'once'; *cmd_select = \&cmd_examine; *cmd_fetch = \&cmd_uid_fetch; +package PublicInbox::IMAP_preauth; +our @ISA = qw(PublicInbox::IMAP); + +sub logged_in { 0 } + 1; diff --git a/lib/PublicInbox/IMAPdeflate.pm b/lib/PublicInbox/IMAPdeflate.pm index 42daa6cffaa..b98a069d9b6 100644 --- a/lib/PublicInbox/IMAPdeflate.pm +++ b/lib/PublicInbox/IMAPdeflate.pm @@ -9,7 +9,6 @@ use warnings; use 5.010_001; use base qw(PublicInbox::IMAP); use Compress::Raw::Zlib; -use Hash::Util qw(unlock_hash); # dependency of fields for perl 5.10+, anyways my %IN_OPT = ( -Bufsize => 1024, @@ -41,7 +40,6 @@ sub enable { $self->write(\"$tag BAD failed to activate compression\r\n"); return; } - unlock_hash(%$self); $self->write(\"$tag OK DEFLATE active\r\n"); bless $self, $class; $self->{zin} = $in;