aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

Payload registry has to do a linear search to find payloads

Open bdraco opened this issue 1 year ago • 4 comments

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

bdraco avatar Oct 04 '24 20:10 bdraco

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.

Dreamsorcerer avatar Oct 05 '24 16:10 Dreamsorcerer

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.

bdraco avatar Oct 05 '24 16:10 bdraco

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.

Dreamsorcerer avatar Oct 05 '24 17:10 Dreamsorcerer

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.

bdraco avatar Oct 05 '24 18:10 bdraco

Looking at this

tab1tha avatar Nov 09 '24 10:11 tab1tha

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

bdraco avatar Nov 10 '24 08:11 bdraco

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

bdraco avatar Nov 10 '24 08:11 bdraco