Skip to content

Add doc for compresslevel of the GZipMiddleware and use compresslevel=5 in the example#11412

Closed
RaphaelMarinier wants to merge 2 commits intofastapi:masterfrom
RaphaelMarinier:patch-1
Closed

Add doc for compresslevel of the GZipMiddleware and use compresslevel=5 in the example#11412
RaphaelMarinier wants to merge 2 commits intofastapi:masterfrom
RaphaelMarinier:patch-1

Conversation

@RaphaelMarinier
Copy link
Copy Markdown

@RaphaelMarinier RaphaelMarinier commented Apr 5, 2024

compresslevel is defined there in starlette's GZipMiddleware:
https://github.com/encode/starlette/blob/4e453ce91940cc7c995e6c728e3fdf341c039056/starlette/middleware/gzip.py#L30

compresslevel=5 is typically a better CPU / compression level tradeoff than 9, e.g. see:
https://tukaani.org/lzma/benchmarks.html

@tiangolo
Copy link
Copy Markdown
Member

tiangolo commented Apr 5, 2024

📝 Docs preview for commit 1ba7288 at: https://12056547.fastapitiangolo.pages.dev

@alejsdev alejsdev added the docs Documentation about how to use FastAPI label Apr 5, 2024
@soulee-dev
Copy link
Copy Markdown
Contributor

Seems like it's duplicated PR #11350

@RaphaelMarinier
Copy link
Copy Markdown
Author

Indeed, it's mostly a duplicate (I was not aware of it), except that the default I propose in the doc is probably a better tradeoff (typically 3x less CPU usage, for only one percent point larger outputs).

@tiangolo
Copy link
Copy Markdown
Member

Thanks @RaphaelMarinier! 🚀

I just merged #11350, but I added compresslevel=5 following your idea. Thanks! ☕

I'll close this one now.

@tiangolo tiangolo closed this Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants