From fcb50073b50aa072ab7e2f8be624d95074028530 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 13 Oct 2020 15:16:49 -0700 Subject: [PATCH] speedup by not writing logfile which will not be saved --- lib/Perl/Tidy/Formatter.pm | 17 +++++++++++++++-- lib/Perl/Tidy/Logger.pm | 18 ++++++++++++++++++ local-docs/Release-Checklist.md | 5 ++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 8717f838..cbfb304d 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -369,6 +369,7 @@ BEGIN { _rseqno_controlling_my_ci_ => $i++, _ris_seqno_controlling_ci_ => $i++, + _save_logfile_ => $i++, }; @@ -671,6 +672,9 @@ sub new { $self->[_rspecial_side_comment_type_] = {}; + # This flag will be updated later by a call to get_save_logfile() + $self->[_save_logfile_] = defined($logger_object); + bless $self, $class; # Safety check..this is not a class yet @@ -4013,6 +4017,13 @@ EOM return; } + # Update the 'save_logfile' flag based to include any tokenization errors. + # We can save time by skipping logfile calls if it is not going to be saved. + my $logger_object = $self->[_logger_object_]; + if ($logger_object) { + $self->[_save_logfile_] = $logger_object->get_save_logfile(); + } + # Make a pass through the lines, looking at lines of CODE and identifying # special processing needs, such format skipping sections marked by # special comments @@ -7004,6 +7015,7 @@ sub process_all_lines { my $file_writer_object = $self->[_file_writer_object_]; my $logger_object = $self->[_logger_object_]; my $vertical_aligner_object = $self->[_vertical_aligner_object_]; + my $save_logfile = $self->[_save_logfile_]; # Note for RT#118553, leave only one newline at the end of a file. # Example code to do this is in comments below: @@ -7103,8 +7115,9 @@ sub process_all_lines { } else { - # let logger see all non-blank lines of code - if ($logger_object) { + # Let logger see all non-blank lines of code. This is a slow operation + # so we avoid it if it is not going to be saved. + if ( $save_logfile && $logger_object ) { $logger_object->black_box( $line_of_tokens, $vertical_aligner_object->get_output_line_number ); } diff --git a/lib/Perl/Tidy/Logger.pm b/lib/Perl/Tidy/Logger.pm index 1763e824..c13947ed 100644 --- a/lib/Perl/Tidy/Logger.pm +++ b/lib/Perl/Tidy/Logger.pm @@ -506,6 +506,24 @@ EOM return; } +sub get_save_logfile { + + # To be called after tokenizer has finished to make formatting more + # efficient. This is not precisely the same as the check used below + # because we don't yet have the syntax check result, but since syntax + # checking is off by default it will be the same except in debug runs with + # syntax checking activated. In that case it will tell the formatter to + # save the logfile even if it may actually be deleted based on the syntax + # check. + my $self = shift; + my $saw_code_bug = $self->{_saw_code_bug}; + my $rOpts = $self->{_rOpts}; + return + $saw_code_bug == 1 + || $rOpts->{'logfile'} + || $rOpts->{'check-syntax'}; +} + sub finish { # called after all formatting to summarize errors diff --git a/local-docs/Release-Checklist.md b/local-docs/Release-Checklist.md index ceeb03b3..6d1e6e04 100644 --- a/local-docs/Release-Checklist.md +++ b/local-docs/Release-Checklist.md @@ -2,7 +2,10 @@ - review tickets at [rt.cpan.org](https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy) - review the issues at [github](https://github.com/perltidy/perltidy/issues/) -- compare the new version with previous version on all files in test area +- compare formatting with the new version with previous version on all files in test area +- run a blinker test (activate option -I and look for 'Blinker' in DIAGNOSTICS) +- run a timing test: compare run time with previous version +- profile with 'nytprof' and compare with previous version - run random testing on final version for a significant time before releasing (several days) - run 'author tests' on a much larger body of code than is covered by the .t files. -- 2.39.5