Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:21:08+00:00 2026-05-13T15:21:08+00:00

This sample script: #!/usr/bin/perl -w while (1) { sleep(1); } takes about 264 kB

  • 0

This sample script:

#!/usr/bin/perl -w

while (1)
{
  sleep(1);
}

takes about 264 kB

grep -A1 heap  /proc/9216/smaps 
0817b000-081bd000 rw-p 0817b000 00:00 0          [heap]
Size:               264 kB

but when I only add my module:

#!/usr/bin/perl -w

use my_module;

while (1)
{
  sleep(1);
}

it takes 18092 kB !

grep -A1 heap  /proc/9219maps 
0817b000-09326000 rw-p 0817b000 00:00 0          [heap]
Size:             18092 kB

Note: The ‘my_module’ has a lot of ‘use module;’ inside it.

How can I find what takes so much memory ?

How can I reduce it ? (using ‘use module (function)’ ?)

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:21:08+00:00Added an answer on May 13, 2026 at 3:21 pm

    Insert BEGIN {} blocks to narrow down the culprit as in

    #! /usr/bin/perl
    
    sub grep_heap { print @_, "\n"; system "grep -A1 heap /proc/$$/smaps" }
    
    BEGIN { grep_heap "<null>" }
    use warnings;
    BEGIN { grep_heap "+warnings" }
    use strict;
    BEGIN { grep_heap "+strict" }
    
    use Data::Dumper;
    BEGIN { grep_heap "+Data::Dumper" }
    use POSIX;
    BEGIN { grep_heap "+POSIX" }
    
    print "Hi\n";
    

    On my Linux host, I see

    $ ./prog.pl
    <null>
    0889b000-088de000 rw-p 0889b000 00:00 0                                  [heap]
    Size:               268 kB
    +warnings
    0889b000-08920000 rw-p 0889b000 00:00 0                                  [heap]
    Size:               532 kB
    +strict
    0889b000-08920000 rw-p 0889b000 00:00 0                                  [heap]
    Size:               532 kB
    +Data::Dumper
    0889b000-089a4000 rw-p 0889b000 00:00 0                                  [heap]
    Size:              1060 kB
    +POSIX
    0889b000-08ace000 rw-p 0889b000 00:00 0                                  [heap]
    Size:              2252 kB
    Hi

    As for what to do about it, you could implement replacement modules with scaled down functionality or ask yourself whether you really need a particular module at all. However, in general, perl’s design prefers to throw memory at problems, and these days it’s common for machines to have multiple gibibytes of main memory.

    Is this resource issue causing performance problems?

    Below is a program that reads through the list of modules in perlmodlib.pod and for each module forks a child to require and import it and check its own heap.

    #! /usr/bin/perl
    
    sub heap {
      my($heap) = @_;
      unless ($heap =~ /^([0-9a-f]+)-([0-9a-f]+)/m) {
        warn "$0: unexpected heap:\n$heap";
        return -1;
      }
      hex($2) - hex($1);
    }
    
    sub size {
      my($bytes) = @_;
    
      my @units = (
        [ MiB   => "%.1f", 1_024 * 1_024 ],
        [ KiB   => "%.1f", 1_024 ],
      );
    
      for (@units) {
        my($unit,$fmt,$n) = @$_;
        return sprintf "$fmt %s" => $bytes/$n, $unit
          if $bytes >= $n;
      }
    
      return "$bytes byte" . ($bytes == 1 ? "" : "s");
    }
    
    my %incr;
    
    my $perlmodlib = `perldoc -l perlmodlib`;
    die "$0: perldoc failed" unless defined $perlmodlib;
    
    my $base = heap `grep heap /proc/$$/smaps`;
    warn "$0: base=" . size($base) . "\n";
    
    chomp $perlmodlib;
    open my $fh, "<", $perlmodlib   or die "$0: open $perlmodlib: $!";
    
    while (<$fh>) {
      next unless /^=head2 Pragmatic Modules/ ..
                  /^=head2 Extension Modules/;
    
      if (/^=item (\w+(::\w+)*)/) {
        my $mod = $1;
        (my $path = "$mod.pm") =~ s!::!/!g;
    
        my $pid = open my $fh, "-|";
        die "$0: fork: $!" unless defined $pid;
    
        if ($pid == 0) {
          open STDERR, ">", "/dev/null" or warn "$0: open: $!";
          exec "perl", "-e", <<EOProgram;
    BEGIN {
      require \"$path\";
      eval { $mod->import };
      system qq(grep heap /proc/\$\$/smaps);
    }
    EOProgram
          die "$0: exec: $!";
        }
        else {
          local $/;
          my $heap = <$fh>;
          unless (defined $heap && length $heap) {
            warn "$0: use $mod failed";
            next;
          }
          $heap = heap $heap;
          $incr{$mod} = $heap > 0 ? $heap-$base : $heap;
        }
      }
    }
    
    foreach my $mod (sort { $incr{$b} <=> $incr{$a} } keys %incr) {
      print "$mod - ", size($incr{$mod}), "\n";
    }
    

    The top few offenders for perl-5.8.8:

    CPAN::Nox - 9.7 MiB
    CPAN - 9.6 MiB
    ExtUtils::MM_VMS - 5.3 MiB
    CPAN::FirstTime - 5.2 MiB
    ExtUtils::Installed - 5.2 MiB
    B::CC - 5.2 MiB
    bigrat - 4.9 MiB
    Math::BigRat - 4.8 MiB
    ExtUtils::MM_NW5 - 4.7 MiB
    ExtUtils::MM_OS2 - 4.6 MiB
    ExtUtils::MM_Win32 - 4.6 MiB
    ExtUtils::MM_Win95 - 4.6 MiB
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Once upon a time the Internet and the SMTP mail… May 14, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer That's valid, however, when using a <thead> it has to… May 14, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer You could handle this in your view: myfile = request.FILES['file']… May 14, 2026 at 6:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.