New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use numeric level id in generated methods #54
Conversation
Added numeric log level id to arguments of generated debug(), info(),... methods. Then it used to avoid extra string-to-id lookups and validation.
We use Log::Dispatch in our application. I did the profiling by Devel::NYTProf and found that a lot of time spent in logging part, converting log-level name to number. Benchmark results (ubuntu 16.04 on i7-2600 CPU @ 3.40GHz)
Benchmark script use strict;
use Benchmark qw(cmpthese);
use Log::Dispatch;
use Log::Dispatch::Null;
my $logger = Log::Dispatch->new;
$logger->add( Log::Dispatch::Null->new(min_level => 'debug') );
cmpthese(-1, {
log_opt => sub { $logger->debug('Test') },
log => sub { $logger->log(level => 'debug', message => 'Test') },
}); |
Thanks for contributing! This looks like a good idea to me: A 10% performance improvement is great! I'm not sure that I like the additional argument to the |
I agree with @preaction. It's not a good design to pass private params to public methods. It's better to split the method into two, one public and one private. Other methods in the same class can call the private method with the optimized params. I think in this case you need to split both the |
lib/Log/Dispatch/Output.pm
Outdated
@@ -129,9 +129,10 @@ sub accepted_levels { | |||
} | |||
|
|||
sub _should_log { | |||
my $self = shift; | |||
my ( $self, $level, $level_id ) = @_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use multiple my $x = shift;
lines.
Also thanks for working on this! |
Okay, this is getting closer, but we can simplify the changes a bit more: Instead of needing to copy the very similar code in both You can do the same with For the |
lib/Log/Dispatch/Output.pm
Outdated
|
||
my $msg_level = $level_id // $self->_level_as_number($level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'//' should be replaced for 5.8 compatibility
Is something more required from my side? |
I did some additional work on this and made a new PR at #55 Thanks for working on this! |
Added numeric log level id to arguments of generated debug(), info(),... methods.
Then it used to avoid extra string-to-id lookups and validation.