attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Eliminate most str.format() and %-formatting

Open hynek opened this issue 1 year ago • 0 comments

Micro-optimization is the root of all success.

hynek avatar Aug 07 '22 11:08 hynek

This btw gives us ~6% performance gain on class creation for simple classes, just by being more idiomatic (and getting rid of the mistake called format).

Measured using:

def create(loops):
    range_it = range(loops)
    d = attrs.define

    t0 = pyperf.perf_counter()

    for _ in range_it:
        @d
        class C:
            a: int
            b: int

    return pyperf.perf_counter() - t0

I presume that more complex classes give us even bigger gainzzz.

hynek avatar Aug 10 '22 10:08 hynek