Payload registry has to do a linear search to find payloads
https://github.com/aio-libs/aiohttp/blob/21f5f92a755dc5ac7225b5e76f561553cf86565e/aiohttp/payload.py#L97
There is a note that its inefficent.
We might be able to clean it up by giving each payload a key as part of the base class and then doing a dict lookup instead
We might be able to clean it up by giving each payload a key as part of the base class and then doing a dict lookup instead
Doesn't really work, because it works with isinstance checks, which could be a subclass or an abc. I thought about this previously and didn't think of any improvements. Not sure what zope.interface is though, might be worth looking into.
Maybe if we have a property that is a key thats the same for the subclassed object.. not sure if that will work. Needs some more thought.
Not sure what you mean, the subclasses are e.g. subclass of bytes or (more realistically) a subclass of io.BufferedIO. They are not our classes, just arbitrary types that might be used to store/stream data.
I need to dig at it a bit more to come up with a solution. This one will take a bit of thought so I opened the issue so I don't forget to come back to it.
Looking at this
We can likely store the payload type() and then do a dict lookup on the type() of the incoming and we get no matches because it's subclasses, fallback to the linear search
We don't have a benchmark for simple post requests which makes this a bit more difficult to quantify what the performance drag of the linear search is. We should add a benchmark first