Open deus-developer opened 2 months ago
I checked the difference between calling synchronous and asynchronous functions, as expected, asynchronous ones are called slower, the difference is 2.8 times (18 ns vs 50 ns on my machine). But such a call is performed once when parsing update, so I think that we can degrade performance by 30 ns in some cases and make all parsing methods asynchronous, even if there is only synchronous code inside. And make them classmethods by the way, why are they static?..
Hello @deus-developer! I'm not a pyrogram developer but am interested in some changes and you've made some of them. For example, I want to refactor the dispatcher, which is what you did in this PR. In your version of the dispatcher, the parser search logic has been changed, previously a dictionary was used, and you perform search using isinstance. I did some experimenting and found that this approach was noticeably slower than dictionary lookups, and since this is a key element of the library, I think performance is important here.
So, finding the parser can take more than a microsecond. Instead of a fixed 25 nanoseconds.
Probably it's not a big performance hit, but other than that, 15 elifs in a row doesn't look very good, and it might be worth going back to using a dictionary.
@KurimuzonAkuma code example