Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the CORE:match (opcode) subroutine in Perl profiling?

I previously wrote some utilities in Perl, and I am now rewriting them in order to give some new/better features. However, things seem to be going much more slowly than in the original utilities, so I decided to run one with the NYTProf profiler. Great profiler btw, still trying to figure out all its useful features.

So anyway, it turns out that 93% of my program's time is being spent on calls to the GeneModel::CORE:match (opcode) subroutine, and I have no idea what this is. Most Google hits point to NYTProf profiles others have posted. I indeed wrote the GeneModel class/package, but I don't know what this subroutine is, why it was called so many times, or why it's taking so long. Any ideas?

like image 615
Daniel Standage Avatar asked Nov 30 '22 09:11

Daniel Standage


2 Answers

CORE:match is a call to a regular expression -- in this case, within your GeneModel package.

For example, if we profile this script, Devel::NYTProf reports 1000 calls to Foo::CORE:match.

use strict;
use warnings;

package Foo;
my $s = 'foo foo';
$s =~ /foo/ for 1 .. 1000;
like image 163
FMc Avatar answered Dec 05 '22 06:12

FMc


Perl is compiled to opcodes. The match operator results in a match opcode.

> perl -MO=Terse -e'm//'
LISTOP (0x8c4b40) leave [1]
    OP (0x8c4070) enter
    COP (0x8c4780) nextstate
    PMOP (0x8c4260) match

This is not a subroutine, but merely represented that way as opcode profiling is a recent addition and the UI hasn't been overhauled yet to take that into account. In simple words, the profiler is telling you that most time is spent in the regex engine.

like image 44
daxim Avatar answered Dec 05 '22 07:12

daxim