]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: preload: load all encodings at startup
authorEric Wong <e@yhbt.net>
Fri, 8 May 2020 01:59:01 +0000 (01:59 +0000)
committerEric Wong <e@yhbt.net>
Sat, 9 May 2020 00:55:25 +0000 (00:55 +0000)
Encode lazy-loads encodings on an as-needed basis.  This is
great for short-lived programs, but leads to fragmentation in
long-lived daemons where immortal allocations can get
interleaved with short-lived, per-request allocations.

Since we have no idea which encodings will be needed when
there's a constant flow of incoming mail, just preload
everything available at startup.

lib/PublicInbox/WWW.pm

index 275e509f2f1136ad62d129e114b245f9c8b75cd4..3a428218f783c85849085a1fec549fcaf260adfc 100644 (file)
@@ -141,6 +141,12 @@ sub call {
 # fragmentation since common allocators favor a large contiguous heap.
 sub preload {
        my ($self) = @_;
+
+       # populate caches used by Encode internally, since emails
+       # may show up with any encoding.
+       require Encode;
+       Encode::find_encoding($_) for Encode->encodings(':all');
+
        require PublicInbox::ExtMsg;
        require PublicInbox::Feed;
        require PublicInbox::View;