[Catalyst] Alternatives to Catalyst ?

Dermot paikkos at googlemail.com
Tue Apr 27 12:22:52 GMT 2010


On 27 April 2010 12:09, Carl Johnstone <catalyst at fadetoblack.me.uk> wrote:
> Dermot wrote:
>> Why wouldn't you, as you write, use the the fastest access methods
>> available? Surely you'd want to develop habits that will a) provide
>> better performance and b) as mentioned below avoid the thorny
>> side-effects of req->params(). This isn't a matter of premature
>> optimisation but simply establishing good practise.
>
> Answering this in the general case.
>
> If you know that the object is stored as a hash, yes you can access it like
> a hash - but that's your risk. When you upgrade your modules and it switches
> to being stored some other way - you get to fix all your code. That's one of
> the things that many perl coders like - to the degree that it's perl
> culture - you *can* poke inside the box if you want but you have to accept
> the risks that go with that.

[meh] I was really trying to avoid coming back into this thread but I
feel I have to make clear what I was asking. There is this assumption
that I *wanted* to break encapsulation. That wasn't the case. I
started from J.Shirely's point. That's was why I left that extract in.

> Benchmark: running all, low, sep for at least 1 CPU seconds...
>       all:  1 wallclock secs ( 1.11 usr +  0.00 sys =  1.11 CPU) @
> 2917341.44/s (n=3238249)
>       low:  0 wallclock secs ( 1.27 usr +  0.04 sys =  1.31 CPU) @
> 12930179.39/s (n=16938535)
>       sep:  1 wallclock secs ( 1.21 usr +  0.01 sys =  1.22 CPU) @
> 3223081.15/s (n=3932159)
>
> Subroutines suck, lets all use hashrefs.

That comment was obviously tongue in cheek but there was an
underlining point that access via sub-routine reference is slower than
access via a hash. Toby was quick to point out that as far as he knew
$req->param->{} was the referred method.  Now that doesn't break
encapsulation and I'm assuming that it will be faster access method
than $req->params(). I could be wrong. I haven't benchmarked. I am
simply following the logic that subroutine references are slower that
hash lookups. Is it really so wrong to want to use params->{} over
params()?  You may call it premature optimisation (as if is a dirty
word) but to me it's just a good habit that has the benefits of being
a bit faster.

So just in case you missed it, when I said:

...but if I'm breaking the encapsulation in some ways that's going to
bite me later, I'd steer
clear.

I meant, "I'd don't want break encapsulation".

I hope that clear things up and you can stop talking about me as if
I'm not here :)

Thanx,
Dp

PS: It goes without saying that I agree with Paul's point.



More information about the Catalyst mailing list