application performance with response_model
See original GitHub issueIssue
I found that when use response_model, application performance dropped dramatically.
no response_model is about 4 times than having response_model in efficiency
How should I solve this problem?
Is my way of using it incorrect?
relative information
py-version: python 3.7
FastAPI-version: lastest
screenshot:
no response_model
with response_model
model code
class ResponseSchema(BaseModel):
code: int
message: str
# config skip_defaults: True
# NovelSchema field count about 10
# ChapterSchema field count about 7
class BookCatalogData(BaseSchema):
novel: NovelSchema = SchemaValue(None)
chapters: List[ChapterSchema] = SchemaValue(None)
class BookCatalogRsm(ResponseSchema):
data: BookCatalogData
controller code
novel field contain 6 field
chapters field contain about 700 items
@app.get(
'/v1/api/book/catalog',
response_model=BookCatalogRsm,
tags=[TAG]
)
async def book_catalog(novelId: int = -1):
chapters = await services.chapter.get_catalog(novelId)
novel = await services.novel.get_by_id(
novelId,
columns=[services.novel.table.c.id, services.novel.table.c.name]
)
return return_ok({
'novel': novel,
'chapters': chapters
})
helping
Thank you for your help.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Response Model - FastAPI
FastAPI framework, high performance, easy to learn, fast to code, ready for production.
Read more >Application of the Graded Response Model to a Scale ... - NCBI
The analysis presented shows the importance of performing modeling with IRT, because it provides in depth information about the psychometric attributes of each ......
Read more >A New LED Response Model and its Application to Pre ...
In this letter, we first propose a new LED response model taking the parasitic effects appearing at higher frequencies into account. The ...
Read more >The Science of the TrainingPeaks Performance Manager
Dr. Andy Coggan explains the incredible science behind the Performance Manager ... Banister's impulse-response model: theory, applications, and limitations.
Read more >Monitoring the Heart Rate Variability Responses to Training ...
Conclusion: The impulse-response model and data collected via a novel smartphone application can be used to model HRV responses to swimming ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, using a response model currently adds a lot of overhead in order to make sure extra fields don’t get serialized. The fix will be to more carefully walk the structure so that fields don’t have to be reparsed.
Fixing this is my top fastapi priority I just haven’t been able to find time to focus on it, but I’m hoping to soon.
out of curiosity what was the reason ? for timing purposes you can use timing-asgi like this