Commit f12c062
committed
[bitreq] Check utf-8 while parsing JSON responses
While deserializing, `serde_json::from_slice` validates utf-8 as
needed. So instead of making two passes on the response body, one
to validate utf-8, and another to deserialize the object, we let
`serde_json::from_slice` check utf-8 as needed during deserialization.
Making a single pass over large response bodies reduces the number of
cache misses, and hence decreases the cycles taken to fully deserialize
such responses.
`Response::json` now returns `Error::SerdeJsonError` instead of
`Error::InvalidUtf8InBody` if invalid utf-8 is found during
deserialization.
For this error case, the `Error::SerdeJsonError` inner type
`serde_json::error::Error` is of category
`serde_json::error::Category::Syntax`. Other JSON syntax errors are
also assigned to this category.
We accept this loss of information given the performance gain described
above.1 parent d31fc06 commit f12c062
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| |||
0 commit comments