Skip to content

Commit 69eb643

Browse files
committed
Parse catalog .dat files as a whole when compiling the backend
Previously Catalog.pm eval'd each individual hash reference so that comments and whitespace can be preserved when running reformat-dat-files. This is unnecessary when building, and we can save ~15% off the run time of genbki.pl by simply slurping and eval'-ing the whole file at once. This saves a bit of time, especially in highly parallel builds, since most build targets depend on this script's outputs. Report and review by Andres Freund Discussion: https://www.postgresql.org/message-id/CAFBsxsGW%3DWRbnxXrc8UqqR479XuxtukSFWV-hnmtgsbuNAUO6w%40mail.gmail.com
1 parent 0324651 commit 69eb643

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ sub ParseData
287287
my $catname = $1;
288288
my $data = [];
289289

290+
if ($preserve_formatting)
291+
{
290292
# Scan the input file.
291293
while (<$ifd>)
292294
{
@@ -341,16 +343,32 @@ sub ParseData
341343
# with --full-tuples to print autogenerated entries, which seems like
342344
# useful behavior for debugging.)
343345
#
344-
# Only keep non-data strings if we are told to preserve formatting.
346+
# Otherwise, we have a non-data string, which we need to keep in
347+
# order to preserve formatting.
345348
if (defined $hash_ref)
346349
{
347350
push @$data, $hash_ref if !$hash_ref->{autogenerated};
348351
}
349-
elsif ($preserve_formatting)
352+
else
350353
{
351354
push @$data, $_;
352355
}
353356
}
357+
}
358+
else
359+
{
360+
# When we only care about the contents, it's faster to read and eval
361+
# the whole file at once.
362+
local $/;
363+
my $full_file = <$ifd>;
364+
eval '$data = ' . $full_file ## no critic (ProhibitStringyEval)
365+
or die "error parsing $input_file\n";
366+
foreach my $hash_ref (@{$data})
367+
{
368+
AddDefaultValues($hash_ref, $schema, $catname);
369+
}
370+
}
371+
354372
close $ifd;
355373

356374
# If this is pg_type, auto-generate array types too.

0 commit comments

Comments
 (0)