[Python-ideas] Dynamic code NOPing

David Stanek dstanek at dstanek.com
Wed Dec 26 05:46:39 CET 2012


On Tue, Dec 25, 2012 at 11:12 PM, Ned Batchelder <ned at nedbatchelder.com>wrote:

> On 12/25/2012 6:04 PM, anatoly techtonik wrote:
>
>> > logger.debug(Message(**factorial, 2, 15))
>>
>> > With this setup, no if statements are needed in your code, and the
>> expensive
>> > computations only occur when required.
>>
>> That's still two function calls and three assignments per logging call.
>> Too expensive and syntax unwieldy. I think everybody agrees now that for
>> existing CPython implementation there is really no solution for the problem
>> of expensive logging calls vs code clarity. You have to implement
>> optimization workaround at the cost of readability.
>>
>
> Anatoly, do you have some measurements to justify the "too expensive"
> claim?  Also, do you have an actual example of expensive logging?  I doubt
> your real code is logging the factorial of 2**15.   What is actually in
> your debug log that is expensive?  It will be much easier to discuss
> solutions if we are talking about actual problems.
>
>
I was thinking the same thing as I read though this thread. I'm typically
logging the result of a calculation and not doing a calculation only
because I'm logging.

On the other hand I have used a homegrown logging system (existed well
before Python's logging module) that allowed the following:

   >>> logger.warn('factorial = %s', lambda: factorial(2**15))

Instead of just outputting the string representation of the lambda the
logger would evaluate the function and str() the return value. Something
like this would be trivial to implement on top of Python's logging module.

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
www: http://dstanek.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121225/bbe03e2a/attachment.html>


More information about the Python-ideas mailing list