Remix.run Logo
leobuskin 8 days ago

As I understand, it may help a bit with logging performance, not sure, still trying to understand the template abilities.

So, right now, you have two options to log:

1. `logger.debug(f'Processing {x}')` - looks great, but evaluates anyway, even if logging level > `logging.DEBUG`;

2. `logger.debug('Processing %s', x)` - won't evaluate till necessary.

What would be the approach with t-strings in this case? Would we get any benefits?

bcoates 8 days ago | parent | next [-]

The expression (x) is eagerly evaluated in both cases, cuz that's how Python works. You can defer the format call but Python fundamentally doesn't have an equivalent of lazy/compile time flag argument evaluation and this doesn't change that.

For a logger t-strings are mostly just a more pleasant and less bug-prone syntax for #2

davepeck 8 days ago | parent | prev [-]

T-strings, like f-strings, are eagerly evaluated -- so in this sense, no, there's no benefit.

trashburger 8 days ago | parent [-]

Not quite; the interpolations are not eagerly stringified which is the potentially expensive part. In this sense it's kind of a middle ground between the two approaches.

davepeck 8 days ago | parent [-]

Sure, good point; I generally think of evaluation, not stringification, as the likely dominant expense. But maybe it’s sometimes the other way around?