]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
favor run_wait() over CORE::system()
authorEric Wong <e@80x24.org>
Sat, 15 Feb 2025 11:10:04 +0000 (11:10 +0000)
committerEric Wong <e@80x24.org>
Mon, 17 Feb 2025 20:09:05 +0000 (20:09 +0000)
run_wait() can use vfork(2) which saves memory in large
processes, such as public-inbox-extindex when dealing with giant
messages.  While vfork is unlikely to matter for real-world uses
of public-inbox-edit, PublicInbox::Spawn is a sunk cost treewide
our `make check-run' test target avoids spawning new Perl
processes for most things in script/*, so there can be a small
savings for testing.

lib/PublicInbox/ExtSearchIdx.pm
script/public-inbox-edit

index d1a16c84f5ae0d3de111c48477ddfeaebc3e8245..7cf600c1f97ca0b15d2871a94028e51a1b34e0fd 100644 (file)
@@ -24,7 +24,7 @@ use File::Glob qw(bsd_glob GLOB_NOSORT);
 use PublicInbox::SQLiteUtil;
 use PublicInbox::Isearch;
 use PublicInbox::MultiGit;
-use PublicInbox::Spawn ();
+use PublicInbox::Spawn qw(run_wait);
 use PublicInbox::Search;
 use PublicInbox::SearchIdx qw(prepare_stack is_ancestor is_bad_blob
        update_checkpoint);
@@ -1266,8 +1266,9 @@ sub idx_init { # similar to V2Writable
        if ($git_midx && ($opt->{'multi-pack-index'} // 1)) {
                my $cmd = $self->git->cmd('multi-pack-index');
                push @$cmd, '--no-progress' if ($opt->{quiet}//0) > 1;
+               push @$cmd, 'write';
                my $lk = $self->lock_for_scope;
-               system(@$cmd, 'write');
+               run_wait $cmd;
                # ignore errors, fairly new command, may not exist
        }
        $self->parallel_init($self->{indexlevel});
index 88115d7cc7757cfea89908a63691089cf31d7219..c76579e4bfa8a14dd8e4a87687677fe9e0343193 100755 (executable)
@@ -15,6 +15,7 @@ PublicInbox::Admin::check_require('-index');
 use PublicInbox::Eml;
 use PublicInbox::InboxWritable qw(eml_from_path);
 use PublicInbox::Import;
+use PublicInbox::Spawn qw(run_wait);
 
 my $help = <<'EOF';
 usage: public-inbox-edit -m MESSAGE-ID [--all] [INBOX_DIRS]
@@ -159,7 +160,7 @@ foreach my $to_edit (values %$found) {
 
        # run the editor, respecting spaces/quote
 retry_edit:
-       if (system(qw(sh -c), $editor.' "$@"', $editor, $edit_fn)) {
+       if (run_wait [qw(sh -c), $editor.' "$@"', $editor, $edit_fn]) {
                if (!(-t STDIN) && !$opt->{force}) {
                        die "E: $editor failed: $?\n";
                }