Skip to content

1s -> 200ms response time fix #347

Closed
@Zaczero

Description

@Zaczero

When profiling the application I have noticed that most of the time is spent on running jsonable encoder from FastAPI. This is a little known fact about FastAPI, but it's much more efficient for methods to return Response instances rather than Python objects which need to be processed through jsonable encoder (to handle nested Pydantic instances etc.). Having applied the fix below, we have noticed a significant performance improvement, especially on large search responses, and I would like to share this "fix" with the upstream:

https://gist.github.com/Zaczero/00f3a2679ebc0a25eb938ed82bc63553

It basically wraps all compatible endpoints, to return Response instances directly (thus skipping the jsonable encoder logic). Cons: this breaks Pydantic support for response objects but it could be worked around by improving the wrapper logic but since it's not used here (afaik), it doesn't really matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions