Commit bf0a4b3
Optimize write path in protocol.py to reduce copies
Refactored `_ProtocolHandler.encode_message` to reduce memory copies and allocations.
- Implemented 'Reserve and Seek' strategy for the write path.
- In uncompressed scenarios (including Protocol V5+), we now write directly to the final buffer instead of an intermediate one, avoiding `bytes` creation and buffer copying.
- Reserved space for the frame header, wrote the body, and then back-filled the header with the correct length.
- Unified buffer initialization and header writing logic for cleaner code.
- Optimized conditional checks for compression support.
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent 0688d6f commit bf0a4b3
1 file changed
Lines changed: 24 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1085 | 1085 | | |
1086 | 1086 | | |
1087 | 1087 | | |
1088 | | - | |
1089 | 1088 | | |
1090 | 1089 | | |
1091 | 1090 | | |
1092 | 1091 | | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | 1092 | | |
1103 | 1093 | | |
1104 | 1094 | | |
| |||
1107 | 1097 | | |
1108 | 1098 | | |
1109 | 1099 | | |
1110 | | - | |
1111 | | - | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1112 | 1122 | | |
| 1123 | + | |
| 1124 | + | |
1113 | 1125 | | |
1114 | 1126 | | |
1115 | 1127 | | |
| |||
0 commit comments