python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

Support for output streaming #528

Open Seemone opened 1 year ago

Seemone commented 1 year ago

I'm using flask-restx in a project that deals with millions of elements in the output using SQLAlchemy as ORM. This has the side effects of flask-restx allocating many GBs of memory and having long peaks of CPU bound computation for large responses, taking tens of seconds before returning anything to the client.

While SQLAlchemy tends to fetch the whole resultset anyway lots of memory could be saved if flask-restx marshalling was done in a stream by generating and sending json elements one by one as the original list passed to marshal() is read, instead of building the whole JSON object and then send it as a whole.