[Python-ideas] Dynamic code NOPing
Ned Batchelder
ned at nedbatchelder.com
Wed Dec 26 05:12:26 CET 2012
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.
>
> The idea is to fix the interpreter, introducing a "feature block" -
> execution block that works only if it is enabled. Execution block
> for logging example below is defined by function name "debug" and
> braces ().
>
> debug( <block contents> )
>
> debug is an object of 'feature' type, which is only
> executed/evaluated, if the feature is enabled in a table of features.
>
This feels both sketchy and strange, and not at all integrated with
existing Python semantics.
--Ned.
More information about the Python-ideas
mailing list