Commit a6413a4
DioCrafts
perf: make BufList::remaining() O(1) by caching total bytes
Add a field to BufList that tracks the total number
of bytes across all buffers. This avoids iterating the entire
VecDeque on every call to remaining(), which is invoked from
hot paths like poll_flush, can_buffer, and advance.
Previously, remaining() was O(n) where n is the number of
buffers in the queue (up to 16 in Queue write strategy).
Now it is O(1) — a simple field read.1 parent 8ba9008 commit a6413a4
1 file changed
+14
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | | - | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| |||
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
| 85 | + | |
81 | 86 | | |
82 | 87 | | |
83 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | | - | |
| 93 | + | |
86 | 94 | | |
| 95 | + | |
| 96 | + | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
| |||
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| 113 | + | |
103 | 114 | | |
104 | 115 | | |
105 | 116 | | |
| |||
0 commit comments