Commit 1a3fb8f
committed
perf: Use response.content to avoid decoding overhead in proxy
Refactors `generate_proxy_response` to forward raw bytes (`response.content`) instead of decoding to string (`response.text`).
This avoids expensive character set detection and decoding/re-encoding cycles, significantly reducing CPU usage for text-based responses.
It also fixes a potential encoding correctness issue where non-UTF-8 responses (e.g., Latin-1) were being forcibly transcoded to UTF-8.
Impact:
- Benchmarks show `response.content` access is ~260x faster than `response.text` for large payloads (0.0005s vs 0.1322s).
- Correctly preserves upstream `Content-Type` charset.1 parent b177828 commit 1a3fb8f
2 files changed
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
91 | | - | |
| 90 | + | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
0 commit comments