Commit b4ac118
committed
Optimize frame body extraction to reduce memory copies
Replace BytesIO.read() with direct buffer slicing to eliminate one
intermediate bytes allocation per received message frame.
Changes:
- Use getbuffer() to get memoryview of underlying buffer
- Slice directly at [body_offset:end_pos] instead of seek+read
- Convert memoryview slice to bytes in single operation
- Maintain buffer position tracking for proper reset behavior
Benefits:
- Eliminates one full-frame allocation on hot receive path
- Particularly impactful for large frames (up to 256MB)
- Maintains compatibility with existing protocol decoder
The memoryview is immediately converted to bytes and released,
preventing buffer resize issues while still gaining the
allocation savings.
Signed-off-by: Yaniv Kaul <ykaul@scylladb.com>1 parent 0b2ad28 commit b4ac118
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1260 | 1260 | | |
1261 | 1261 | | |
1262 | 1262 | | |
1263 | | - | |
1264 | | - | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
1265 | 1269 | | |
1266 | 1270 | | |
1267 | 1271 | | |
| |||
0 commit comments