RT::Require faster implementation of eval "require ..."

Hello.
Attached patch represent new function RT::Require which implement
eval “require $module”. This implementation check "$module::VERSION"
before running eval.
I also wrote small perfomance test. Attached.
Results:
Rate Simple eval Eval with check
Simple eval 31056/s – -70%
Eval with check 105263/s 239% –

It shows that my code runs ~3 times faster when module allready loaded.

		Best regards. Ruslan.

require_test.pl (661 Bytes)

rt-require.patch (2.46 KB)

Hello.
Attached patch represent new function RT::Require which implement
eval “require $module”. This implementation check
“$module::VERSION”
before running eval.

It shows that my code runs ~3 times faster when module allready
loaded.

Is this change just because it’s “neat” or because you’ve actually run
into a measurable delay with the current method? To my knowledge, RT
doesn’t do any "require"s in a tight loop. From your perf tests, it
looks like the standard method is already pretty fast, relative to
everything else that RT’s doing.

Best,
Jesse

Jesse Vincent wrote:

Hello.
Attached patch represent new function RT::Require which implement
eval “require $module”. This implementation check
“$module::VERSION”
before running eval.

It shows that my code runs ~3 times faster when module allready
loaded.

Is this change just because it’s “neat” or because you’ve actually run
into a measurable delay with the current method? To my knowledge, RT
doesn’t do any "require"s in a tight loop. From your perf tests, it
looks like the standard method is already pretty fast, relative to
everything else that RT’s doing.

  1. it’s neat. May be only for me.
  2. it could be used not only while other dynamic loading.
  3. it checks existence before evaling, it’s better in any case.
  4. I don’t think that this case when features are more bad then good.
  5. You could skip it in any case.
    Best regards. Ruslan.

Jesse Vincent wrote:

Hello.
Attached patch represent new function RT::Require which implement
eval “require $module”. This implementation check “$module::VERSION”
before running eval.

It shows that my code runs ~3 times faster when module allready
loaded.
Is this change just because it’s “neat” or because you’ve actually run
into a measurable delay with the current method? To my knowledge, RT
doesn’t do any "require"s in a tight loop. From your perf tests, it
looks like the standard method is already pretty fast, relative to
everything else that RT’s doing.

  1. it’s neat. May be only for me.
  2. it could be used not only while other dynamic loading.
  3. it checks existence before evaling, it’s better in any case.
  4. I don’t think that this case when features are more bad then good.
  5. You could skip it in any case.

nod If it actually provides a performance improvement over eval
without any downside, then it probably makes sense as a CPAN module or
possibly a perl core patch.