Closed erdewit closed 6 years ago
This seems like a good idea, I'm not entirely sure what the debug flag is even for if it's not for this.
That being said I've thought about migrating everything to the brace style adapter pattern which would then only format messages that are actually printed, (so if the loglevel is set to ERROR even info messages don't use much).
OTOH it's adding 2 levels of indirection (the style adapter and the BraceMessage class), so I figured it might very well be slower, so I went with YAGNI.
Additionally there's f-strings... which can't be made lazy (without lots of hacks), but format much faster (since the format string is parsed at compile time, among other reasons.). Also would have to drop support for python 3.5... which maybe isn't a big deal... but I'm not sure it would be worth it.
Though... comparing all these things (especially if you using something really exotic, like macropy), might make a good blog post.
Some profiling of a custom benchmark that I use for distex shows that quamash spends most of its time in formatting debug messages, even when they're not used. This PR makes the formatting conditional on the debug setting of the loop. The
timerEvent()
method has also been streamlined a bit.The benchmark goes from 7000 reps/s to over 14000 with these changes. For comparison, the standard asyncio loop does 31000 reps/s and uvloop up to 50000.