Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

We don't know one millionth of one percent about anything.


devel / comp.lang.python / Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

SubjectAuthor
o Re: Ref-strings in logging messages (was: Performance issue withJulian Smith

1
Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)

<mailman.538.1665177814.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19667&group=comp.lang.python#19667

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jul...@op59.net (Julian Smith)
Newsgroups: comp.lang.python
Subject: Re: Ref-strings in logging messages (was: Performance issue with
CPython 3.10 + Cython)
Date: Fri, 7 Oct 2022 21:12:42 +0100
Lines: 44
Message-ID: <mailman.538.1665177814.20444.python-list@python.org>
References: <f583eefa-ef36-a59b-7b33-928d67e49f06@mrabarnett.plus.com>
<FC32E4B4-6B96-44BC-ACE6-C0EF2E93242B@barrys-emacs.org>
<20221007211242.23ede455.jules@op59.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de leEMPaiwRh9aSgTkorShGQbkeG4eLaBQp1TARlUwr7Iw==
Return-Path: <jules@op59.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.027
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '2022': 0.05; 'parent':
0.07; 'enabled': 0.09; 'lazy': 0.09; 'skip:` 20': 0.09; 'log':
0.12; '2022,': 0.16; 'arguments': 0.16; 'barry': 0.16;
'efficiently': 0.16; 'evaluating': 0.16; 'expressions': 0.16;
'frame,': 0.16; 'montanaro': 0.16; 'runtime': 0.16; 'slow': 0.16;
'subject:3.10': 0.16; 'subject:CPython': 0.16; 'subject:Cython':
0.16; 'subject:issue': 0.16; 'subject:logging': 0.16; 'wrote:':
0.16; 'probably': 0.17; 'uses': 0.19; 'calls': 0.19; 'to:addr
:python-list': 0.20; 'fri,': 0.22; 'code': 0.23; 'discussion':
0.25; 'seems': 0.26; '>>>': 0.28; 'am,': 0.31; 'module': 0.31;
'guess': 0.32; 'received:46': 0.32; "i'm": 0.33; 'there': 0.33;
'header:In-Reply-To:1': 0.34; 'using': 0.37; "it's": 0.37;
'though': 0.37; 'way': 0.38; 'could': 0.38; 'quite': 0.39; 'use':
0.39; 'case.': 0.40; 'gone': 0.40; 'me.': 0.62; 'received:82':
0.62; 'pass': 0.64; 'url:a': 0.64; 'well': 0.65; 'items': 0.68;
'url:net': 0.68; 'obvious': 0.69; 'compared': 0.71; 'features.':
0.76; 'formatting': 0.76; 'extra': 0.84; 'admit': 0.84;
'generation.': 0.84; 'locals': 0.84; 'subject: \n ': 0.84;
'subject:Performance': 0.84; 'url:f': 0.86; 'url:p': 0.88;
'expensive': 0.91
In-Reply-To: <FC32E4B4-6B96-44BC-ACE6-C0EF2E93242B@barrys-emacs.org>
X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-unknown-openbsd7.0)
X-BlackCat-Spam-Score: 9
X-Spam-Status: No, score=0.9
X-Mailman-Approved-At: Fri, 07 Oct 2022 17:23:32 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20221007211242.23ede455.jules@op59.net>
X-Mailman-Original-References: <f583eefa-ef36-a59b-7b33-928d67e49f06@mrabarnett.plus.com>
<FC32E4B4-6B96-44BC-ACE6-C0EF2E93242B@barrys-emacs.org>
 by: Julian Smith - Fri, 7 Oct 2022 20:12 UTC

On Fri, 7 Oct 2022 18:28:06 +0100
Barry <barry@barrys-emacs.org> wrote:

> > On 7 Oct 2022, at 18:16, MRAB <python@mrabarnett.plus.com> wrote:
> >
> > On 2022-10-07 16:45, Skip Montanaro wrote:
> >>> On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames <andreas.0815.qwertz@gmail.com>
> >>> wrote:
> >>> 1. The culprit was me. As lazy as I am, I have used f-strings all over the
> >>> place in calls to `logging.logger.debug()` and friends, evaluating all
> >>> arguments regardless of whether the logger was enabled or not.
> >>>
> >> I thought there was some discussion about whether and how to efficiently
> >> admit f-strings to the logging package. I'm guessing that's not gone
> >> anywhere (yet).
> > Letting you pass in a callable to call might help because that you could use lambda.
>
> Yep, that’s the obvious way to avoid expensive log data generation.
> Would need logging module to support that use case.

I have some logging code that uses eval() to evaluate expressions using
locals and globals in a parent stack frame, together with a parser to
find `{...}` items in a string.

I guess this constitutes a (basic) runtime implementation of f-strings.
As such it can avoid expensive evaluation/parsing when disabled, though
it's probably slow when enabled compared to native f-strings. It seems
to work quite well in practise, and also allows one to add some extra
formatting features.

For details see:

https://git.ghostscript.com/?p=mupdf.git;a=blob;f=scripts/jlib.py;h=e85e9f2c4;hb=HEAD#l41

- Jules

--
http://op59.net

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor